Changed bookmark category return result

This commit is contained in:
Alex Zolotarev 2012-10-08 17:27:09 +03:00 committed by Alex Zolotarev
parent 595d46b6a1
commit 358b242d61
3 changed files with 16 additions and 11 deletions

View file

@ -73,14 +73,14 @@ public:
static string GenerateUniqueFileName(const string & path, string const & name);
};
/// <category name, bookmark index>
typedef pair<string, int> BookmarkAndCategory;
/// <category index, bookmark index>
typedef pair<int, int> BookmarkAndCategory;
inline BookmarkAndCategory MakeEmptyBookmarkAndCategory()
{
return BookmarkAndCategory(string(), int(-1));
return BookmarkAndCategory(int(-1), int(-1));
}
inline bool IsValid(BookmarkAndCategory const & bmc)
{
return (!bmc.first.empty() && bmc.second >= 0);
return (bmc.first >= 0 && bmc.second >= 0);
}

View file

@ -416,8 +416,8 @@ BookmarkAndCategory Framework::GetBookmark(m2::PointD pxPoint, double visualScal
m2::RectD rect(PtoG(m2::PointD(pxPoint.x - sm, pxPoint.y - sm)),
PtoG(m2::PointD(pxPoint.x + sm, pxPoint.y + sm)));
int retBookmarkCategory = -1;
int retBookmark = -1;
string retBookmarkCategory;
double minD = numeric_limits<double>::max();
for (size_t i = 0; i < m_bookmarks.size(); ++i)
@ -433,8 +433,8 @@ BookmarkAndCategory Framework::GetBookmark(m2::PointD pxPoint, double visualScal
double const d = rect.Center().SquareLength(pt);
if (d < minD)
{
retBookmarkCategory = static_cast<int>(i);
retBookmark = static_cast<int>(j);
retBookmarkCategory = m_bookmarks[i]->GetName();
minD = d;
}
}

View file

@ -180,7 +180,8 @@ UNIT_TEST(Bookmarks_Getting)
BookmarkAndCategory res = fm.GetBookmark(fm.GtoP(m2::PointD(40, 20)), 1.0);
TEST(IsValid(res), ());
TEST_EQUAL(res.second, 0, ());
TEST_EQUAL(res.first, "cat2" , ());
TEST_EQUAL(res.first, 1 , ());
TEST_EQUAL(fm.GetBmCategory(res.first)->GetName(), "cat2", ());
res = fm.GetBookmark(fm.GtoP(m2::PointD(0, 0)), 1.0);
TEST(!IsValid(res), ());
@ -189,7 +190,8 @@ UNIT_TEST(Bookmarks_Getting)
res = fm.GetBookmark(fm.GtoP(m2::PointD(41, 40)), 1.0);
TEST(IsValid(res), ());
TEST_EQUAL(res.first, "cat3", ());
TEST_EQUAL(res.first, 2, ());
TEST_EQUAL(fm.GetBmCategory(res.first)->GetName(), "cat3", ());
Bookmark const * bm = fm.GetBmCategory(res.first)->GetBookmark(res.second);
TEST_EQUAL(bm->GetName(), "3", ());
TEST_EQUAL(bm->GetType(), "placemark-red", ());
@ -271,14 +273,16 @@ UNIT_TEST(Bookmarks_AddingMoving)
BookmarkAndCategory res = fm.GetBookmark(pixelPoint, 1.0);
TEST(IsValid(res), ());
TEST_EQUAL(res.second, 0, ());
TEST_EQUAL(res.first, categoryOne, ());
TEST_EQUAL(res.first, 0, ());
TEST_EQUAL(fm.GetBmCategory(res.first)->GetName(), categoryOne, ());
// Edit the name and type of bookmark
fm.AddBookmark(categoryOne, Bookmark(globalPoint, "name2", "placemark-blue"));
res = fm.GetBookmark(pixelPoint, 1.0);
TEST(IsValid(res), ());
TEST_EQUAL(res.second, 0, ());
TEST_EQUAL(res.first, categoryOne, ());
TEST_EQUAL(res.first, 0, ());
TEST_EQUAL(fm.GetBmCategory(res.first)->GetName(), categoryOne, ());
Bookmark const * pBm = fm.GetBmCategory(res.first)->GetBookmark(res.second);
TEST_EQUAL(pBm->GetName(), "name2", ());
TEST_EQUAL(pBm->GetType(), "placemark-blue", ());
@ -289,7 +293,8 @@ UNIT_TEST(Bookmarks_AddingMoving)
res = fm.GetBookmark(pixelPoint, 1.0);
TEST(IsValid(res), ());
TEST_EQUAL(res.second, 0, ());
TEST_EQUAL(res.first, categoryTwo, ());
TEST_EQUAL(res.first, 1, ());
TEST_EQUAL(fm.GetBmCategory(res.first)->GetName(), categoryTwo, ());
TEST_EQUAL(fm.GetBmCategory(categoryOne)->GetBookmarksCount(), 0,
("Bookmark wasn't moved from one category to another"));
pBm = fm.GetBmCategory(res.first)->GetBookmark(res.second);