From f72c92d4181c1f57265cf2a5cf2c720798ba5637 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joan=20Sol=C3=A0?= <jsola@iri.upc.edu> Date: Mon, 21 Dec 2020 21:06:04 +0100 Subject: [PATCH] Fix conditions for Capture::move() --- src/capture/capture_base.cpp | 6 ++---- test/gtest_capture_base.cpp | 24 +++++++++++++++++++++++- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/src/capture/capture_base.cpp b/src/capture/capture_base.cpp index 03bc1c480..957ed68d0 100644 --- a/src/capture/capture_base.cpp +++ b/src/capture/capture_base.cpp @@ -177,11 +177,9 @@ void CaptureBase::unfix() void CaptureBase::move(FrameBasePtr _frm_ptr) { - WOLF_WARN_COND(this->getFrame() == nullptr, "moving a capture not linked to any frame. Consider just linking it with link() instead of move()!"); + WOLF_WARN_COND(this->getFrame() == nullptr, "Moving Capture ", id(), " at ts=", getTimeStamp(), " not linked to any frame. Consider just linking it with link() instead of move()!"); - assert((this->getFrame() == nullptr || not this->getFrame()->getProblem()) && "Forbidden: moving a capture already linked to a KF"); - assert((_frm_ptr != nullptr) && "Forbidden: moving a capture to a null frame"); - assert((_frm_ptr != nullptr && _frm_ptr->getProblem()) && "Forbidden: moving a capture to a non-estimated frame"); + assert((this->getFrame() == nullptr || not this->getFrame()->getProblem()) && "Forbidden: trying to move a capture already linked to a KF!"); // Unlink if (this->getFrame()) diff --git a/test/gtest_capture_base.cpp b/test/gtest_capture_base.cpp index d114c7441..3a0cbc455 100644 --- a/test/gtest_capture_base.cpp +++ b/test/gtest_capture_base.cpp @@ -119,6 +119,7 @@ TEST(CaptureBase, move_from_F_to_KF) ASSERT_EQ(KF->getCaptureList().size(), 2); ASSERT_EQ(F->getCaptureList().size(), 0); + ASSERT_TRUE(C->getProblem()); } TEST(CaptureBase, move_from_F_to_null) @@ -133,7 +134,10 @@ TEST(CaptureBase, move_from_F_to_null) ASSERT_EQ(F->getCaptureList().size(), 1); - ASSERT_DEATH( C->move(F0), ""); + C->move(F0); + + ASSERT_EQ(F->getCaptureList().size(), 0); + ASSERT_FALSE(C->getProblem()); } TEST(CaptureBase, move_from_null_to_KF) @@ -151,6 +155,7 @@ TEST(CaptureBase, move_from_null_to_KF) C->move(KF); ASSERT_EQ(KF->getCaptureList().size(), 2); + ASSERT_TRUE(C->getProblem()); } TEST(CaptureBase, move_from_null_to_F) @@ -161,6 +166,23 @@ TEST(CaptureBase, move_from_null_to_F) auto C = std::make_shared<CaptureBase>("Dummy", 0.0); + C->move(F); + + ASSERT_EQ(F->getCaptureList().size(), 1); + + ASSERT_FALSE(C->getProblem()); +} + +TEST(CaptureBase, move_from_KF_to_F) +{ + ProblemPtr problem = Problem::create("PO", 2); + + auto KF = problem->emplaceFrame(0.0); // dummy F object + + auto F = std::make_shared<FrameBase>(0.0, nullptr); // dummy F object + + auto C = CaptureBase::emplace<CaptureBase>(KF, "Dummy", 0.0); + ASSERT_DEATH(C->move(F), ""); } -- GitLab