From 0befb81458d49547ab4b288ba38b31af2788c84d Mon Sep 17 00:00:00 2001 From: ExMix Date: Tue, 13 May 2014 13:38:02 +0300 Subject: [PATCH] tests and desckop app adaptation --- map/map.pro | 8 +- map/map_tests/bookmarks_test.cpp | 180 +++++++++------- map/map_tests/kmz_unarchive_test.cpp | 3 +- map/map_tests/mwm_url_tests.cpp | 296 +++++++++++++++------------ qt/draw_widget.cpp | 12 +- qt/search_panel.cpp | 12 +- 6 files changed, 283 insertions(+), 228 deletions(-) diff --git a/map/map.pro b/map/map.pro index 7c3f0703d5..6a871ab0b1 100644 --- a/map/map.pro +++ b/map/map.pro @@ -64,7 +64,9 @@ HEADERS += \ scales_processor.hpp \ yopme_render_policy.hpp \ track.hpp \ - alfa_animation_task.hpp + alfa_animation_task.hpp \ + user_mark_container.hpp \ + user_mark.hpp SOURCES += \ feature_vec_model.cpp \ @@ -115,7 +117,9 @@ SOURCES += \ scales_processor.cpp \ yopme_render_policy.cpp \ track.cpp \ - alfa_animation_task.cpp + alfa_animation_task.cpp \ + user_mark_container.cpp \ + user_mark.cpp !iphone*:!tizen*:!android* { HEADERS += qgl_render_context.hpp diff --git a/map/map_tests/bookmarks_test.cpp b/map/map_tests/bookmarks_test.cpp index 3831d80149..ff2bd67c5e 100644 --- a/map/map_tests/bookmarks_test.cpp +++ b/map/map_tests/bookmarks_test.cpp @@ -153,7 +153,8 @@ char const * kmlString = UNIT_TEST(Bookmarks_ImportKML) { - BookmarkCategory cat("Default"); + Framework framework; + BookmarkCategory cat("Default", framework); TEST(cat.LoadFromKML(new MemReader(kmlString, strlen(kmlString))), ()); CheckBookmarks(cat); @@ -167,7 +168,8 @@ UNIT_TEST(Bookmarks_ExportKML) { char const * BOOKMARKS_FILE_NAME = "UnitTestBookmarks.kml"; - BookmarkCategory cat("Default"); + Framework framework; + BookmarkCategory cat("Default", framework); TEST(cat.LoadFromKML(new MemReader(kmlString, strlen(kmlString))), ()); CheckBookmarks(cat); @@ -188,7 +190,7 @@ UNIT_TEST(Bookmarks_ExportKML) CheckBookmarks(cat); TEST_EQUAL(cat.IsVisible(), true, ()); - scoped_ptr cat2(BookmarkCategory::CreateFromKMLFile(BOOKMARKS_FILE_NAME)); + scoped_ptr cat2(BookmarkCategory::CreateFromKMLFile(BOOKMARKS_FILE_NAME, framework)); CheckBookmarks(*cat2); cat2->SaveToKMLFile(); @@ -198,7 +200,7 @@ UNIT_TEST(Bookmarks_ExportKML) // MapName is the tag in test kml data. string const catFileName = GetPlatform().SettingsDir() + "MapName.kml"; - cat2.reset(BookmarkCategory::CreateFromKMLFile(catFileName)); + cat2.reset(BookmarkCategory::CreateFromKMLFile(catFileName, framework)); CheckBookmarks(*cat2); TEST(my::DeleteFileX(catFileName), ()); } @@ -212,10 +214,44 @@ namespace FileWriter::DeleteFileX(path + arrFiles[i] + BOOKMARKS_FILE_EXTENSION); } - Bookmark const * GetBookmark(Framework const & fm, m2::PointD const & pt) + UserMark const * GetMark(Framework & fm, m2::PointD const & pt) { - BookmarkAndCategory const res = fm.GetBookmark(fm.GtoP(pt), 1.0); - return fm.GetBmCategory(res.first)->GetBookmark(res.second); + m2::AnyRectD rect; + fm.GetNavigator().GetTouchRect(fm.GtoP(pt), 20, rect); + return fm.GetBookmarkManager().FindNearestUserMark(rect); + } + + Bookmark const * GetBookmark(Framework & fm, m2::PointD const & pt) + { + UserMark const * mark = GetMark(fm, pt); + ASSERT(mark != NULL, ()); + ASSERT(mark->GetContainer() != NULL, ()); + ASSERT(mark->GetContainer()->GetType() == UserMarkContainer::BOOKMARK_MARK, ()); + return static_cast(mark); + } + + Bookmark const * GetBookmarkPxPoint(Framework & fm, m2::PointD const & pt) + { + return GetBookmark(fm, fm.PtoG(pt)); + } + + BookmarkCategory const * GetCategory(Bookmark const * bm) + { + ASSERT(bm->GetContainer() != NULL, ()); + ASSERT(bm->GetContainer()->GetType() == UserMarkContainer::BOOKMARK_MARK, ()); + return static_cast(bm->GetContainer()); + } + + bool IsValidBookmark(Framework & fm, m2::PointD const & pt) + { + UserMark const * mark = GetMark(fm, pt); + if (mark == NULL) + return false; + + if (mark->GetContainer()->GetType() != UserMarkContainer::BOOKMARK_MARK) + return false; + + return true; } } @@ -226,19 +262,19 @@ UNIT_TEST(Bookmarks_Timestamp) char const * arrCat[] = { "cat", "cat1" }; - Bookmark b1(orgPoint, "name", "type"); + BookmarkCustomData b1("name", "type"); fm.AddCategory(arrCat[0]); - fm.AddBookmark(0, b1); + fm.AddBookmark(0, orgPoint, b1); Bookmark const * pBm = GetBookmark(fm, orgPoint); time_t const timeStamp = pBm->GetTimeStamp(); TEST_NOT_EQUAL(timeStamp, my::INVALID_TIME_STAMP, ()); - Bookmark b3(orgPoint, "newName", "newType"); + BookmarkCustomData b3("newName", "newType"); b3.SetTimeStamp(12345); TEST_NOT_EQUAL(b3.GetTimeStamp(), timeStamp, ()); - fm.AddBookmark(0, b3); + fm.AddBookmark(0, orgPoint, b3); pBm = GetBookmark(fm, orgPoint); TEST_EQUAL(pBm->GetTimeStamp(), timeStamp, ()); @@ -247,7 +283,7 @@ UNIT_TEST(Bookmarks_Timestamp) TEST_NOT_EQUAL(b3.GetTimeStamp(), timeStamp, ()); fm.AddCategory(arrCat[1]); - fm.AddBookmark(1, b3); + fm.AddBookmark(1, orgPoint, b3); TEST_EQUAL(fm.GetBmCategory(0)->GetBookmark(0)->GetName(), "name", ()); TEST_EQUAL(fm.GetBmCategory(0)->GetBookmark(0)->GetType(), "type", ()); @@ -280,14 +316,14 @@ UNIT_TEST(Bookmarks_Getting) for (int i = 0; i < 3; ++i) fm.AddCategory(arrCat[i]); - Bookmark bm(m2::PointD(38, 20), "1", "placemark-red"); - fm.AddBookmark(0, bm); + BookmarkCustomData bm("1", "placemark-red"); + fm.AddBookmark(0, m2::PointD(38, 20), bm); BookmarkCategory const * c1 = fm.GetBmCategory(0); - bm = Bookmark(m2::PointD(41, 20), "2", "placemark-red"); - fm.AddBookmark(1, bm); + bm = BookmarkCustomData("2", "placemark-red"); + fm.AddBookmark(1, m2::PointD(41, 20), bm); BookmarkCategory const * c2 = fm.GetBmCategory(1); - bm = Bookmark(m2::PointD(41, 40), "3", "placemark-red"); - fm.AddBookmark(2, bm); + bm = BookmarkCustomData("3", "placemark-red"); + fm.AddBookmark(2, m2::PointD(41, 40), bm); BookmarkCategory const * c3 = fm.GetBmCategory(2); @@ -298,43 +334,34 @@ UNIT_TEST(Bookmarks_Getting) (void)fm.GetBmCategory(4); TEST_EQUAL(fm.GetBmCategoriesCount(), 3, ()); - BookmarkAndCategory res = fm.GetBookmark(fm.GtoP(m2::PointD(40, 20)), 1.0); - TEST(IsValid(res), ()); - TEST_EQUAL(res.second, 0, ()); - TEST_EQUAL(res.first, 1 , ()); - TEST_EQUAL(fm.GetBmCategory(res.first)->GetName(), arrCat[1], ()); + Bookmark const * mark = GetBookmark(fm, m2::PointD(40, 20)); + BookmarkCategory const * cat = GetCategory(mark); - res = fm.GetBookmark(fm.GtoP(m2::PointD(0, 0)), 1.0); - TEST(!IsValid(res), ()); - res = fm.GetBookmark(fm.GtoP(m2::PointD(800, 400)), 1.0); - TEST(!IsValid(res), ()); + TEST_EQUAL(cat->GetName(), arrCat[1], ()); - res = fm.GetBookmark(fm.GtoP(m2::PointD(41, 40)), 1.0); - TEST(IsValid(res), ()); - TEST_EQUAL(res.first, 2, ()); - TEST_EQUAL(fm.GetBmCategory(res.first)->GetName(), arrCat[2], ()); - Bookmark const * pBm = fm.GetBmCategory(res.first)->GetBookmark(res.second); - TEST_EQUAL(pBm->GetName(), "3", ()); - TEST_EQUAL(pBm->GetType(), "placemark-red", ()); + TEST(!IsValidBookmark(fm, m2::PointD(0, 0)), ()); + TEST(!IsValidBookmark(fm, m2::PointD(800, 400)), ()); - bm = Bookmark(m2::PointD(41, 40), "4", "placemark-blue"); - fm.AddBookmark(2, bm); + TEST(IsValidBookmark(fm, m2::PointD(41, 40)), ()); + mark = GetBookmark(fm, m2::PointD(41, 40)); + cat = GetCategory(mark); + TEST_EQUAL(cat->GetName(), arrCat[2], ()); + + bm = BookmarkCustomData("4", "placemark-blue"); + fm.AddBookmark(2, m2::PointD(41, 40), bm); BookmarkCategory const * c33 = fm.GetBmCategory(2); TEST_EQUAL(c33, c3, ()); - res = fm.GetBookmark(fm.GtoP(m2::PointD(41, 40)), 1.0); - TEST(IsValid(res), ()); - BookmarkCategory * cat = fm.GetBmCategory(res.first); - TEST(cat, ()); - pBm = cat->GetBookmark(res.second); + mark = GetBookmark(fm, m2::PointD(41, 40)); + cat = GetCategory(mark); //should find first valid result, there two results with the same coordinates 3 and 4 - TEST_EQUAL(pBm->GetName(), "3", ()); - TEST_EQUAL(pBm->GetType(), "placemark-red", ()); + TEST_EQUAL(mark->GetName(), "3", ()); + TEST_EQUAL(mark->GetType(), "placemark-red", ()); TEST_EQUAL(cat->GetBookmarksCount(), 2, ()); - cat->DeleteBookmark(0); + fm.GetBmCategory(2)->DeleteBookmark(0); TEST_EQUAL(cat->GetBookmarksCount(), 1, ()); DeleteCategoryFiles(arrCat); @@ -463,44 +490,36 @@ UNIT_TEST(Bookmarks_AddingMoving) m2::PointD const globalPoint = m2::PointD(40, 20); m2::PointD const pixelPoint = fm.GtoP(globalPoint); - Bookmark bm(globalPoint, "name", "placemark-red"); - fm.AddBookmark(0, bm); + BookmarkCustomData bm("name", "placemark-red"); + fm.AddBookmark(0, globalPoint, bm); BookmarkCategory const * c1 = fm.GetBmCategory(0); - BookmarkAndCategory res = fm.GetBookmark(pixelPoint, 1.0); - TEST(IsValid(res), ()); - TEST_EQUAL(res.second, 0, ()); - TEST_EQUAL(res.first, 0, ()); - TEST_EQUAL(fm.GetBmCategory(res.first)->GetName(), arrCat[0], ()); + Bookmark const * mark = GetBookmarkPxPoint(fm, pixelPoint); + BookmarkCategory const * cat = GetCategory(mark); + TEST_EQUAL(cat->GetName(), arrCat[0], ()); - bm = Bookmark(globalPoint, "name2", "placemark-blue"); - fm.AddBookmark(0, bm); + bm = BookmarkCustomData("name2", "placemark-blue"); + fm.AddBookmark(0, globalPoint, bm); BookmarkCategory const * c11 = fm.GetBmCategory(0); TEST_EQUAL(c1, c11, ()); - res = fm.GetBookmark(pixelPoint, 1.0); - TEST(IsValid(res), ()); - TEST_EQUAL(res.second, 0, ()); - TEST_EQUAL(res.first, 0, ()); - TEST_EQUAL(fm.GetBmCategory(res.first)->GetName(), arrCat[0], ()); - Bookmark const * pBm = fm.GetBmCategory(res.first)->GetBookmark(res.second); - TEST_EQUAL(pBm->GetName(), "name", ()); - TEST_EQUAL(pBm->GetType(), "placemark-red", ()); + mark = GetBookmarkPxPoint(fm, pixelPoint); + cat = GetCategory(mark); + TEST_EQUAL(cat->GetName(), arrCat[0], ()); + TEST_EQUAL(mark->GetName(), "name", ()); + TEST_EQUAL(mark->GetType(), "placemark-red", ()); // Edit name, type and category of bookmark - bm = Bookmark(globalPoint, "name3", "placemark-green"); - fm.AddBookmark(1, bm); + bm = BookmarkCustomData("name3", "placemark-green"); + fm.AddBookmark(1, globalPoint, bm); BookmarkCategory const * c2 = fm.GetBmCategory(1); TEST_NOT_EQUAL(c1, c2, ()); TEST_EQUAL(fm.GetBmCategoriesCount(), 2, ()); - res = fm.GetBookmark(pixelPoint, 1.0); - TEST(IsValid(res), ()); - TEST_EQUAL(res.second, 0, ()); - TEST_EQUAL(res.first, 0, ()); - TEST_EQUAL(fm.GetBmCategory(res.first)->GetName(), arrCat[0], ()); + mark = GetBookmarkPxPoint(fm, pixelPoint); + cat = GetCategory(mark); + TEST_EQUAL(cat->GetName(), arrCat[0], ()); TEST_EQUAL(fm.GetBmCategory(0)->GetBookmarksCount(), 2, ("Bookmark wasn't moved from one category to another")); - pBm = fm.GetBmCategory(res.first)->GetBookmark(res.second); - TEST_EQUAL(pBm->GetName(), "name", ()); - TEST_EQUAL(pBm->GetType(), "placemark-red", ()); + TEST_EQUAL(mark->GetName(), "name", ()); + TEST_EQUAL(mark->GetType(), "placemark-red", ()); DeleteCategoryFiles(arrCat); } @@ -536,7 +555,8 @@ char const * kmlString2 = UNIT_TEST(Bookmarks_InnerFolder) { - BookmarkCategory cat("Default"); + Framework framework; + BookmarkCategory cat("Default", framework); TEST(cat.LoadFromKML(new MemReader(kmlString2, strlen(kmlString2))), ()); TEST_EQUAL(cat.GetBookmarksCount(), 1, ()); @@ -544,8 +564,9 @@ UNIT_TEST(Bookmarks_InnerFolder) UNIT_TEST(BookmarkCategory_EmptyName) { - BookmarkCategory * pCat = new BookmarkCategory(""); - pCat->AddBookmark(Bookmark(m2::PointD(0, 0), "", "placemark-red")); + Framework framework; + BookmarkCategory * pCat = new BookmarkCategory("", framework); + pCat->AddBookmark(m2::PointD(0, 0), BookmarkCustomData("", "placemark-red")); pCat->SaveToKMLFile(); pCat->SetName("xxx"); @@ -593,13 +614,14 @@ char const * kmlString3 = UNIT_TEST(Bookmarks_SpecialXMLNames) { - BookmarkCategory cat1(""); + Framework framework; + BookmarkCategory cat1("", framework); TEST(cat1.LoadFromKML(new MemReader(kmlString3, strlen(kmlString3))), ()); TEST_EQUAL(cat1.GetBookmarksCount(), 1, ()); TEST(cat1.SaveToKMLFile(), ()); - scoped_ptr cat2(BookmarkCategory::CreateFromKMLFile(cat1.GetFileName())); + scoped_ptr cat2(BookmarkCategory::CreateFromKMLFile(cat1.GetFileName(), framework)); TEST(cat2.get(), ()); TEST_EQUAL(cat2->GetBookmarksCount(), 1, ()); @@ -624,8 +646,9 @@ bool AlmostEqual(double const & a, double const & b) UNIT_TEST(TrackParsingTest_1) { + Framework framework; string const KML = GetPlatform().SettingsPathForFile("kml-with-track-kml.test"); - BookmarkCategory * cat = BookmarkCategory::CreateFromKMLFile(KML); + BookmarkCategory * cat = BookmarkCategory::CreateFromKMLFile(KML, framework); if (!cat) TEST(false, ("Category can't be created")); TEST_EQUAL(cat->GetTracksCount(), 4, ()); @@ -647,8 +670,9 @@ UNIT_TEST(TrackParsingTest_1) UNIT_TEST(TrackParsingTest_2) { + Framework framework; string const KML = GetPlatform().SettingsPathForFile("kml-with-track-from-google-earth.test"); - BookmarkCategory * cat = BookmarkCategory::CreateFromKMLFile(KML); + BookmarkCategory * cat = BookmarkCategory::CreateFromKMLFile(KML, framework); if (!cat) TEST(false, ("Category can't be created")); TEST_EQUAL(cat->GetTracksCount(), 1, ()); diff --git a/map/map_tests/kmz_unarchive_test.cpp b/map/map_tests/kmz_unarchive_test.cpp index ae84cc26ef..f3c5a0d408 100644 --- a/map/map_tests/kmz_unarchive_test.cpp +++ b/map/map_tests/kmz_unarchive_test.cpp @@ -31,7 +31,8 @@ UNIT_TEST(Open_KMZ_Test) MY_SCOPE_GUARD(fileGuard, bind(&FileWriter::DeleteFileX, KMLFILE)); ZipFileReader::UnzipFile(KMZFILE, "doc.kml", KMLFILE); - BookmarkCategory cat("Default"); + Framework framework; + BookmarkCategory cat("Default", framework); TEST(cat.LoadFromKML(new FileReader(KMLFILE)), ()); TEST_EQUAL(files.size(), 6, ("KMZ file wrong number of files")); diff --git a/map/map_tests/mwm_url_tests.cpp b/map/map_tests/mwm_url_tests.cpp index 45b1edfab6..1e090cd919 100644 --- a/map/map_tests/mwm_url_tests.cpp +++ b/map/map_tests/mwm_url_tests.cpp @@ -1,5 +1,6 @@ #include "../../testing/testing.hpp" +#include "../framework.hpp" #include "../mwm_url.hpp" #include "../../coding/uri.hpp" @@ -9,126 +10,208 @@ using namespace url_scheme; +namespace +{ + void ToMercatoToLatLon(double & lat, double & lon) + { + lon = MercatorBounds::XToLon(MercatorBounds::LonToX(lon)); + lat = MercatorBounds::YToLat(MercatorBounds::LatToY(lat)); + } + + const UserMarkContainer::Type type = UserMarkContainer::API_MARK; + class ApiTest + { + public: + ApiTest(string const & uriString) + { + m_m = &m_fm.GetBookmarkManager(); + m_c = &m_m->UserMarksGetController(type); + m_api.SetController(m_c); + m_api.SetUriAndParse(uriString); + } + + bool IsValid() const { return m_api.IsValid(); } + m2::RectD GetViewport() + { + m2::RectD rect; + ScalesProcessor scales; + m_api.GetViewportRect(scales, rect); + return rect; + } + string const & GetAppTitle() { return m_api.GetAppTitle(); } + bool GoBackOnBalloonClick() { return m_api.GoBackOnBalloonClick(); } + int GetPointCount() { return m_c->GetUserMarkCount(); } + string const & GetGlobalBackUrl() { return m_api.GetGlobalBackUrl(); } + int GetApiVersion() { return m_api.GetApiVersion(); } + bool TestLatLon(int index, double lat, double lon) const + { + double tLat, tLon; + GetMark(index)->GetLatLon(tLat, tLon); + return my::AlmostEqual(tLat, lat) && my::AlmostEqual(tLon, lon); + } + + bool TestName(int index, string const & name) + { + return GetData(index).GetName() == name; + } + + bool TestID(int index, string const & id) + { + return GetData(index).GetID() == id; + } + + private: + UserMark const * GetMark(int index) const + { + TEST_LESS(index, m_c->GetUserMarkCount(), ()); + return m_c->GetUserMark(index); + } + + ApiCustomData const & GetData(int index) const + { + UserMark const * mark = GetMark(index); + TEST_NOT_EQUAL(mark->GetContainer(), NULL, ()); + TEST_EQUAL(mark->GetContainer()->GetType(), type, ()); + TEST_EQUAL(mark->GetCustomData().GetType(), UserCustomData::API, ()); + return static_cast(mark->GetCustomData()); + } + + private: + Framework m_fm; + ParsedMapApi m_api; + UserMarkContainer::Controller * m_c; + BookmarkManager * m_m; + }; + + bool IsValid(Framework & fm, string const & uriStrig) + { + ParsedMapApi api; + UserMarkContainer::Type type = UserMarkContainer::API_MARK; + api.SetController(&fm.GetBookmarkManager().UserMarksGetController(type)); + api.SetUriAndParse(uriStrig); + bool res = api.IsValid(); + fm.GetBookmarkManager().UserMarksClear(type); + return res; + } +} + UNIT_TEST(MapApiSmoke) { - Uri uri("mapswithme://map?ll=38.970559,-9.419289&ignoreThisParam=Yes&z=17&n=Point%20Name"); - TEST(uri.IsValid(), ()); + string uriString = "mapswithme://map?ll=38.970559,-9.419289&ignoreThisParam=Yes&z=17&n=Point%20Name"; + TEST(Uri(uriString).IsValid(), ()); - ParsedMapApi api(uri); - TEST(api.IsValid(), ()); - TEST_EQUAL(api.GetPoints().size(), 1, ()); - TEST_EQUAL(api.GetPoints()[0].m_lat, 38.970559, ()); - TEST_EQUAL(api.GetPoints()[0].m_lon, -9.419289, ()); - TEST_EQUAL(api.GetPoints()[0].m_name, "Point Name", ()); - TEST_EQUAL(api.GetPoints()[0].m_id, "", ()); - TEST_EQUAL(api.GetGlobalBackUrl(), "", ()); + ApiTest test(uriString); + + TEST(test.IsValid(), ()); + TEST_EQUAL(test.GetPointCount(), 1, ()); + TEST(test.TestLatLon(0, 38.970559, -9.419289), ()); + TEST(test.TestName(0, "Point Name"), ()); + TEST(test.TestID(0, ""), ()); + TEST_EQUAL(test.GetGlobalBackUrl(), "", ()); } UNIT_TEST(MapApiInvalidUrl) { - TEST(!ParsedMapApi(Uri("competitors://map?ll=12.3,34.54")).IsValid(), ()); - TEST(!ParsedMapApi(Uri("mapswithme://ggg?ll=12.3,34.54")).IsValid(), ()); - TEST(!ParsedMapApi(Uri("mwm://")).IsValid(), ("No path")); - TEST(!ParsedMapApi(Uri("mapswithme://map?")).IsValid(), ("No parameters")); - TEST(!ParsedMapApi(Uri("mapswithme://map?ll=23.55")).IsValid(), ("No longtitude")); - TEST(!ParsedMapApi(Uri("mapswithme://map?ll=1,2,3")).IsValid(), ("Too many values for ll")); + Framework fm; + 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")); + TEST(!IsValid(fm, "mapswithme://map?"), ("No longtitude")); + TEST(!IsValid(fm, "mapswithme://map?ll=1,2,3"), ("Too many values for ll")); } UNIT_TEST(MapApiLatLonLimits) { - TEST(!ParsedMapApi(Uri("mapswithme://map?ll=-91,10")).IsValid(), ("Invalid latitude")); - TEST(!ParsedMapApi(Uri("mwm://map?ll=523.55,10")).IsValid(), ("Invalid latitude")); - TEST(!ParsedMapApi(Uri("mapswithme://map?ll=23.55,450")).IsValid(), ("Invalid longtitude")); - TEST(!ParsedMapApi(Uri("mapswithme://map?ll=23.55,-450")).IsValid(), ("Invalid longtitude")); + Framework fm; + 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")); + TEST(!IsValid(fm, "mapswithme://map?ll=23.55,-450"), ("Invalid longtitude")); } UNIT_TEST(MapApiPointNameBeforeLatLon) { - ParsedMapApi api(Uri("mapswithme://map?n=Name&ll=1,2")); - TEST(api.IsValid(), ()); - TEST_EQUAL(api.GetPoints().size(), 1, ()); - TEST_EQUAL(api.GetPoints()[0].m_name, "", ()); + ApiTest test("mapswithme://map?n=Name&ll=1,2"); + TEST(test.IsValid(), ()); + TEST_EQUAL(test.GetPointCount(), 1, ()); + TEST(test.TestName(0, ""), ()); } UNIT_TEST(MapApiPointNameOverwritten) { - ParsedMapApi api(Uri("mapswithme://map?ll=1,2&n=A&N=B")); + ApiTest api("mapswithme://map?ll=1,2&n=A&N=B"); TEST(api.IsValid(), ()); - TEST_EQUAL(api.GetPoints().size(), 1, ()); - TEST_EQUAL(api.GetPoints()[0].m_name, "B", ()); + TEST_EQUAL(api.GetPointCount(), 1, ()); + TEST(api.TestName(0, "B"), ()); } UNIT_TEST(MapApiMultiplePoints) { - ParsedMapApi api(Uri("mwm://map?ll=1.1,1.2&n=A&LL=2.1,2.2&ll=-3.1,-3.2&n=C")); + ApiTest api("mwm://map?ll=1.1,1.2&n=A&LL=2.1,2.2&ll=-3.1,-3.2&n=C"); TEST(api.IsValid(), ()); - TEST_EQUAL(api.GetPoints().size(), 3, ()); - TEST_EQUAL(api.GetPoints()[0].m_lat, 1.1, ()); - TEST_EQUAL(api.GetPoints()[0].m_lon, 1.2, ()); - TEST_EQUAL(api.GetPoints()[0].m_name, "A", ()); - TEST_EQUAL(api.GetPoints()[1].m_name, "", ()); - TEST_EQUAL(api.GetPoints()[1].m_lat, 2.1, ()); - TEST_EQUAL(api.GetPoints()[1].m_lon, 2.2, ()); - TEST_EQUAL(api.GetPoints()[2].m_name, "C", ()); - TEST_EQUAL(api.GetPoints()[2].m_lat, -3.1, ()); - TEST_EQUAL(api.GetPoints()[2].m_lon, -3.2, ()); + TEST_EQUAL(api.GetPointCount(), 3, ()); + TEST(api.TestLatLon(0, 1.1, 1.2), ()); + TEST(api.TestName(0, "A"), ()); + TEST(api.TestLatLon(1, 2.1, 2.2), ()); + TEST(api.TestName(1, ""), ()); + TEST(api.TestLatLon(2, -3.1, -3.2), ()); + TEST(api.TestName(2, "C"), ()); } UNIT_TEST(MapApiInvalidPointLatLonButValidOtherParts) { - ParsedMapApi api(Uri("mapswithme://map?ll=1,1,1&n=A&ll=2,2&n=B&ll=3,3,3&n=C")); + ApiTest api("mapswithme://map?ll=1,1,1&n=A&ll=2,2&n=B&ll=3,3,3&n=C"); TEST(api.IsValid(), ()); - TEST_EQUAL(api.GetPoints().size(), 1, ()); - TEST_EQUAL(api.GetPoints()[0].m_lat, 2, ()); - TEST_EQUAL(api.GetPoints()[0].m_lon, 2, ()); - TEST_EQUAL(api.GetPoints()[0].m_name, "B", ()); + TEST_EQUAL(api.GetPointCount(), 1, ()); + TEST(api.TestLatLon(0, 2, 2), ()); + TEST(api.TestName(0, "B"), ()); } UNIT_TEST(MapApiPointURLEncoded) { - ParsedMapApi api(Uri("mwm://map?ll=1,2&n=%D0%9C%D0%B8%D0%BD%D1%81%D0%BA&id=http%3A%2F%2Fmap%3Fll%3D1%2C2%26n%3Dtest")); + ApiTest api("mwm://map?ll=1,2&n=%D0%9C%D0%B8%D0%BD%D1%81%D0%BA&id=http%3A%2F%2Fmap%3Fll%3D1%2C2%26n%3Dtest"); TEST(api.IsValid(), ()); - TEST_EQUAL(api.GetPoints().size(), 1, ()); - TEST_EQUAL(api.GetPoints()[0].m_name, "\xd0\x9c\xd0\xb8\xd0\xbd\xd1\x81\xd0\xba", ()); - TEST_EQUAL(api.GetPoints()[0].m_id, "http://map?ll=1,2&n=test", ()); + TEST_EQUAL(api.GetPointCount(), 1, ()); + TEST(api.TestName(0, "\xd0\x9c\xd0\xb8\xd0\xbd\xd1\x81\xd0\xba"), ()); + TEST(api.TestID(0, "http://map?ll=1,2&n=test"), ()); } UNIT_TEST(GlobalBackUrl) { { - ParsedMapApi api(Uri("mwm://map?ll=1,2&n=PointName&backurl=someTestAppBackUrl")); + ApiTest api("mwm://map?ll=1,2&n=PointName&backurl=someTestAppBackUrl"); TEST_EQUAL(api.GetGlobalBackUrl(), "someTestAppBackUrl://", ()); } { - ParsedMapApi api(Uri("mwm://map?ll=1,2&n=PointName&backurl=ge0://")); + ApiTest api("mwm://map?ll=1,2&n=PointName&backurl=ge0://"); TEST_EQUAL(api.GetGlobalBackUrl(), "ge0://", ()); } { - ParsedMapApi api(Uri("mwm://map?ll=1,2&n=PointName&backurl=ge0%3A%2F%2F")); + ApiTest api("mwm://map?ll=1,2&n=PointName&backurl=ge0%3A%2F%2F"); TEST_EQUAL(api.GetGlobalBackUrl(), "ge0://", ()); } { - ParsedMapApi api(Uri("mwm://map?ll=1,2&n=PointName&backurl=http://mapswithme.com")); + ApiTest api("mwm://map?ll=1,2&n=PointName&backurl=http://mapswithme.com"); TEST_EQUAL(api.GetGlobalBackUrl(), "http://mapswithme.com", ()); } { - ParsedMapApi api(Uri("mwm://map?ll=1,2&n=PointName&backUrl=someapp://%D0%9C%D0%BE%D0%B1%D0%B8%D0%BB%D1%8C%D0%BD%D1%8B%D0%B5%20%D0%9A%D0%B0%D1%80%D1%82%D1%8B")); + ApiTest api("mwm://map?ll=1,2&n=PointName&backUrl=someapp://%D0%9C%D0%BE%D0%B1%D0%B8%D0%BB%D1%8C%D0%BD%D1%8B%D0%B5%20%D0%9A%D0%B0%D1%80%D1%82%D1%8B"); TEST_EQUAL(api.GetGlobalBackUrl(), "someapp://\xd0\x9c\xd0\xbe\xd0\xb1\xd0\xb8\xd0\xbb\xd1\x8c\xd0\xbd\xd1\x8b\xd0\xb5 \xd0\x9a\xd0\xb0\xd1\x80\xd1\x82\xd1\x8b", ()); } { - ParsedMapApi api(Uri("mwm://map?ll=1,2&n=PointName")); + ApiTest api("mwm://map?ll=1,2&n=PointName"); TEST_EQUAL(api.GetGlobalBackUrl(), "", ()); } { - ParsedMapApi api(Uri("mwm://map?ll=1,2&n=PointName&backurl=%D0%BF%D1%80%D0%B8%D0%BB%D0%BE%D0%B6%D0%B5%D0%BD%D0%B8%D0%B5%3A%2F%2F%D0%BE%D1%82%D0%BA%D1%80%D0%BE%D0%B9%D0%A1%D1%81%D1%8B%D0%BB%D0%BA%D1%83")); + ApiTest api("mwm://map?ll=1,2&n=PointName&backurl=%D0%BF%D1%80%D0%B8%D0%BB%D0%BE%D0%B6%D0%B5%D0%BD%D0%B8%D0%B5%3A%2F%2F%D0%BE%D1%82%D0%BA%D1%80%D0%BE%D0%B9%D0%A1%D1%81%D1%8B%D0%BB%D0%BA%D1%83"); TEST_EQUAL(api.GetGlobalBackUrl(), "приложение://откройСсылку", ()); } { - ParsedMapApi api(Uri("mwm://map?ll=1,2&n=PointName&backurl=%D0%BF%D1%80%D0%B8%D0%BB%D0%BE%D0%B6%D0%B5%D0%BD%D0%B8%D0%B5%3A%2F%2F%D0%BE%D1%82%D0%BA%D1%80%D0%BE%D0%B9%D0%A1%D1%81%D1%8B%D0%BB%D0%BA%D1%83")); + ApiTest api("mwm://map?ll=1,2&n=PointName&backurl=%D0%BF%D1%80%D0%B8%D0%BB%D0%BE%D0%B6%D0%B5%D0%BD%D0%B8%D0%B5%3A%2F%2F%D0%BE%D1%82%D0%BA%D1%80%D0%BE%D0%B9%D0%A1%D1%81%D1%8B%D0%BB%D0%BA%D1%83"); TEST_EQUAL(api.GetGlobalBackUrl(), "приложение://откройСсылку", ()); } { - ParsedMapApi api(Uri("mwm://map?ll=1,2&n=PointName&backurl=%E6%88%91%E6%84%9Bmapswithme")); + ApiTest api("mwm://map?ll=1,2&n=PointName&backurl=%E6%88%91%E6%84%9Bmapswithme"); TEST_EQUAL(api.GetGlobalBackUrl(), "我愛mapswithme://", ()); } } @@ -136,23 +219,23 @@ UNIT_TEST(GlobalBackUrl) UNIT_TEST(VersionTest) { { - ParsedMapApi api(Uri("mwm://map?ll=1,2&v=1&n=PointName")); + ApiTest api("mwm://map?ll=1,2&v=1&n=PointName"); TEST_EQUAL(api.GetApiVersion(), 1, ()); } { - ParsedMapApi api(Uri("mwm://map?ll=1,2&v=kotik&n=PointName")); + ApiTest api("mwm://map?ll=1,2&v=kotik&n=PointName"); TEST_EQUAL(api.GetApiVersion(), 0, ()); } { - ParsedMapApi api(Uri("mwm://map?ll=1,2&v=APacanyVoobsheKotjata&n=PointName")); + ApiTest api("mwm://map?ll=1,2&v=APacanyVoobsheKotjata&n=PointName"); TEST_EQUAL(api.GetApiVersion(), 0, ()); } { - ParsedMapApi api(Uri("mwm://map?ll=1,2&n=PointName")); + ApiTest api("mwm://map?ll=1,2&n=PointName"); TEST_EQUAL(api.GetApiVersion(), 0, ()); } { - ParsedMapApi api(Uri("mwm://map?V=666&ll=1,2&n=PointName")); + ApiTest api("mwm://map?V=666&ll=1,2&n=PointName"); TEST_EQUAL(api.GetApiVersion(), 666, ()); } } @@ -160,60 +243,19 @@ UNIT_TEST(VersionTest) UNIT_TEST(AppNameTest) { { - ParsedMapApi api(Uri("mwm://map?ll=1,2&v=1&n=PointName&appname=Google")); + ApiTest api("mwm://map?ll=1,2&v=1&n=PointName&appname=Google"); TEST_EQUAL(api.GetAppTitle(), "Google", ()); } { - ParsedMapApi api(Uri("mwm://map?ll=1,2&v=1&n=PointName&AppName=%D0%AF%D0%BD%D0%B4%D0%B5%D0%BA%D1%81")); + ApiTest api("mwm://map?ll=1,2&v=1&n=PointName&AppName=%D0%AF%D0%BD%D0%B4%D0%B5%D0%BA%D1%81"); TEST_EQUAL(api.GetAppTitle(), "Яндекс", ()); } { - ParsedMapApi api(Uri("mwm://map?ll=1,2&v=1&n=PointName")); + ApiTest api("mwm://map?ll=1,2&v=1&n=PointName"); TEST_EQUAL(api.GetAppTitle(), "", ()); } } -UNIT_TEST(RectTest) -{ - { - ParsedMapApi api(Uri("mwm://map?ll=0,0")); - m2::RectD rect = api.GetLatLonRect(); - TEST_EQUAL(rect.maxX(), 0, ()); - TEST_EQUAL(rect.maxY(), 0, ()); - TEST_EQUAL(rect.minX(), 0, ()); - TEST_EQUAL(rect.minX(), 0, ()); - } - { - ParsedMapApi api(Uri("mwm://map?ll=0,0&ll=1,1&ll=2,2&ll=3,3&ll=4,4&ll=5,5&")); - m2::RectD rect = api.GetLatLonRect(); - TEST_EQUAL(rect.maxX(), 5, ()); - TEST_EQUAL(rect.maxY(), 5, ()); - TEST_EQUAL(rect.minX(), 0, ()); - TEST_EQUAL(rect.minX(), 0, ()); - } - { - ParsedMapApi api(Uri("mwm://map?ll=-90,90&ll=90,-90")); - m2::RectD rect = api.GetLatLonRect(); - TEST_EQUAL(rect.maxX(), 90, ()); - TEST_EQUAL(rect.maxY(), 90, ()); - TEST_EQUAL(rect.minX(), -90, ()); - TEST_EQUAL(rect.minX(), -90, ()); - } - { - ParsedMapApi api(Uri("mwm://map?ll=180,180&ll=0,0&ll=-180,-180")); - m2::RectD rect = api.GetLatLonRect(); - TEST_EQUAL(rect.maxX(), 0, ()); - TEST_EQUAL(rect.maxY(), 0, ()); - TEST_EQUAL(rect.minX(), 0, ()); - TEST_EQUAL(rect.minX(), 0, ()); - } - { - ParsedMapApi api(Uri("mwm://")); - m2::RectD rect = api.GetLatLonRect(); - TEST(!rect.IsValid(), ()); - } -} - namespace { string generatePartOfUrl(url_scheme::ApiPoint const & point) @@ -252,16 +294,21 @@ void generateRandomTest(size_t numberOfPoints, size_t stringLength) string result = "mapswithme://map?v=1"; for (size_t i = 0; i < vect.size(); ++i) result += generatePartOfUrl(vect[i]); - Uri uri(result); - ParsedMapApi api(uri); - vector const & points = api.GetPoints(); - TEST_EQUAL(points.size(), vect.size(), ()); + + ApiTest api(result); + TEST_EQUAL(api.GetPointCount(), vect.size(), ()); for (size_t i = 0; i < vect.size();++i) { - TEST_EQUAL(points[i].m_lat, vect[i].m_lat, ()); - TEST_EQUAL(points[i].m_lon, vect[i].m_lon, ()); - TEST_EQUAL(points[i].m_name, vect[i].m_name, ()); - TEST_EQUAL(points[i].m_id, vect[i].m_id, ()); + /// Mercator defined not on all range of lat\lon values. + /// Some part of lat\lon is clamp on convertation + /// By this we convert source data lat\lon to mercator and then into lat\lon + /// to emulate core convertions + double lat = vect[i].m_lat; + double lon = vect[i].m_lon; + ToMercatoToLatLon(lat, lon); + TEST(api.TestLatLon(i, lat, lon), ()); + TEST(api.TestName(i, vect[i].m_name), ()); + TEST(api.TestID(i, vect[i].m_id), ()); } TEST_EQUAL(api.GetApiVersion(), 1, ()); } @@ -278,37 +325,22 @@ UNIT_TEST(StressTestRandomTest) generateRandomTest(10000, 100); } -UNIT_TEST(MWMApiZoomLevelTest) -{ - m2::RectD const r1 = ParsedMapApi(Uri("mwm://map?ll=0,0")).GetLatLonRect(); - m2::RectD const r2 = ParsedMapApi(Uri("mwm://map?z=14&ll=0,0")).GetLatLonRect(); - TEST_EQUAL(r1, r2, ()); - - m2::RectD const r3 = ParsedMapApi(Uri("mwm://map?ll=1,1&z=14")).GetLatLonRect(); - TEST_NOT_EQUAL(r2, r3, ()); - TEST_NOT_EQUAL(r1, r3, ()); -} - UNIT_TEST(MWMApiBalloonActionDefaultTest) { { - Uri uri("mapswithme://map?ll=38.970559,-9.419289&ignoreThisParam=Yes&z=17&n=Point%20Name"); - ParsedMapApi api(uri); + ApiTest api("mapswithme://map?ll=38.970559,-9.419289&ignoreThisParam=Yes&z=17&n=Point%20Name"); TEST(!api.GoBackOnBalloonClick(), ("")); } { - Uri uri("mapswithme://map?ll=38.970559,-9.419289&ignoreThisParam=Yes&z=17&n=Point%20Name&balloonAction=false"); - ParsedMapApi api(uri); + ApiTest api("mapswithme://map?ll=38.970559,-9.419289&ignoreThisParam=Yes&z=17&n=Point%20Name&balloonAction=false"); TEST(api.GoBackOnBalloonClick(), ("")); } { - Uri uri("mapswithme://map?ll=38.970559,-9.419289&ignoreThisParam=Yes&z=17&n=Point%20Name&balloonAction=true"); - ParsedMapApi api(uri); + ApiTest api("mapswithme://map?ll=38.970559,-9.419289&ignoreThisParam=Yes&z=17&n=Point%20Name&balloonAction=true"); TEST(api.GoBackOnBalloonClick(), ("")); } { - Uri uri("mapswithme://map?ll=38.970559,-9.419289&ignoreThisParam=Yes&z=17&n=Point%20Name&balloonAction="); - ParsedMapApi api(uri); + ApiTest api("mapswithme://map?ll=38.970559,-9.419289&ignoreThisParam=Yes&z=17&n=Point%20Name&balloonAction="); TEST(api.GoBackOnBalloonClick(), ("")); } } diff --git a/qt/draw_widget.cpp b/qt/draw_widget.cpp index 53252c920f..58c19ab6c3 100644 --- a/qt/draw_widget.cpp +++ b/qt/draw_widget.cpp @@ -68,11 +68,7 @@ namespace qt m_frameFn(); } - void DummyAPI(url_scheme::ApiPoint const &) {} - void DummyBookmark(BookmarkAndCategory const &) {} - void DummyPOI(m2::PointD const &, search::AddressInfo const &) {} - void DummyPosition(double, double) {} - void DummyAdditional(size_t) {} + void DummyUserMark(UserMark const * ){} void DummyDismiss() {} DrawWidget::DrawWidget(QWidget * pParent) @@ -88,11 +84,7 @@ namespace qt { // Initialize with some stubs for test. PinClickManager & manager = GetBalloonManager(); - manager.ConnectApiListener(&DummyAPI); - manager.ConnectBookmarkListener(&DummyBookmark); - manager.ConnectPoiListener(&DummyPOI); - manager.ConnectPositionListener(&DummyPosition); - manager.ConnectAdditionalListener(&DummyAdditional); + manager.ConnectUserMarkListener(&DummyUserMark); manager.ConnectDismissListener(&DummyDismiss); } diff --git a/qt/search_panel.cpp b/qt/search_panel.cpp index 7fa69e4ae4..8be3aced46 100644 --- a/qt/search_panel.cpp +++ b/qt/search_panel.cpp @@ -2,6 +2,8 @@ #include "draw_widget.hpp" #include "../map/measurement_utils.hpp" +#include "../map/bookmark_manager.hpp" +#include "../map/user_mark_container.hpp" #include "../std/bind.hpp" @@ -93,7 +95,7 @@ void SearchPanel::ClearResults() m_pTable->setRowCount(0); m_results.clear(); - m_pDrawWidget->GetFramework().AdditionalPoiLayerClear(); + m_pDrawWidget->GetFramework().GetBookmarkManager().UserMarksClear(UserMarkContainer::SEARCH_MARK); } void SearchPanel::OnSearchResult(ResultsT * res) @@ -114,6 +116,7 @@ void SearchPanel::OnSearchResult(ResultsT * res) ClearResults(); Framework & frm = m_pDrawWidget->GetFramework(); + BookmarkManager & manager = frm.GetBookmarkManager(); for (ResultsT::IterT i = res->Begin(); i != res->End(); ++i) { @@ -126,10 +129,9 @@ void SearchPanel::OnSearchResult(ResultsT * res) if (e.GetResultType() != ResultT::RESULT_SUGGESTION) { + UserMark * mark = manager.UserMarksAddMark(UserMarkContainer::SEARCH_MARK, e.GetFeatureCenter()); + mark->InjectCustomData(new SearchCustomData(e.GetString(), "", "")); // For debug purposes: add bookmarks for search results - Bookmark bm(e.GetFeatureCenter(), e.GetString(), "placemark-red"); - frm.AdditionalPoiLayerAddPoi(bm); - m_pTable->setItem(rowCount, 0, create_item(QString::fromUtf8(e.GetFeatureType()))); m_pTable->setItem(rowCount, 3, create_item(m_pDrawWidget->GetDistance(e).c_str())); @@ -197,7 +199,7 @@ void SearchPanel::showEvent(QShowEvent *) void SearchPanel::hideEvent(QHideEvent *) { - m_pDrawWidget->GetFramework().AdditionalPoiLayerClear(); + m_pDrawWidget->GetFramework().GetBookmarkManager().UserMarksClear(UserMarkContainer::SEARCH_MARK); disconnect(m_pDrawWidget, SIGNAL(ViewportChanged()), this, SLOT(OnViewportChanged()));