Skip to content
Snippets Groups Projects
Commit 5e2874a5 authored by Joan Solà Ortega's avatar Joan Solà Ortega
Browse files

Fix asserts in CaptureBase::move()

parent 7ec4574e
No related branches found
No related tags found
1 merge request!403Resolve "Merge Aux/KeyFrames into Estimated Frames"
Pipeline #6214 passed
......@@ -177,11 +177,11 @@ void CaptureBase::unfix()
void CaptureBase::move(FrameBasePtr _frm_ptr)
{
WOLF_WARN_COND(this->getFrame() == nullptr, "moving a capture not linked to any frame");
WOLF_WARN_COND(_frm_ptr == nullptr, "moving a capture to a null FrameBasePtr");
WOLF_WARN_COND(this->getFrame() == nullptr, "moving a capture not linked to any frame. Consider just linking it with link() instead of move()!");
assert((this->getFrame() == nullptr || this->getFrame()->getProblem()) && "Forbidden: moving a capture already linked to a KF");
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: 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");
// Unlink
if (this->getFrame())
......
......@@ -100,6 +100,71 @@ TEST(CaptureBase, process)
ASSERT_TRUE(C->process()); // This should not fail (although it does nothing)
}
TEST(CaptureBase, move_from_F_to_KF)
{
ProblemPtr problem = Problem::create("PO", 2);
auto KF = problem->emplaceFrame(0.0); // dummy F object
auto KC = CaptureBase::emplace<CaptureBase>(KF, "Dummy", 0.0);
auto F = std::make_shared<FrameBase>(0.0, nullptr); // dummy F object
auto C = CaptureBase::emplace<CaptureBase>(F, "Dummy", 0.0);
ASSERT_EQ(KF->getCaptureList().size(), 1);
ASSERT_EQ(F->getCaptureList().size(), 1);
C->move(KF);
ASSERT_EQ(KF->getCaptureList().size(), 2);
ASSERT_EQ(F->getCaptureList().size(), 0);
}
TEST(CaptureBase, move_from_F_to_null)
{
ProblemPtr problem = Problem::create("PO", 2);
FrameBasePtr F0 = nullptr;
auto F = std::make_shared<FrameBase>(0.0, nullptr); // dummy F object
auto C = CaptureBase::emplace<CaptureBase>(F, "Dummy", 0.0);
ASSERT_EQ(F->getCaptureList().size(), 1);
ASSERT_DEATH( C->move(F0), "");
}
TEST(CaptureBase, move_from_null_to_KF)
{
ProblemPtr problem = Problem::create("PO", 2);
auto KF = problem->emplaceFrame(0.0); // dummy F object
auto KC = CaptureBase::emplace<CaptureBase>(KF, "Dummy", 0.0);
auto C = std::make_shared<CaptureBase>("Dummy", 0.0);
ASSERT_EQ(KF->getCaptureList().size(), 1);
C->move(KF);
ASSERT_EQ(KF->getCaptureList().size(), 2);
}
TEST(CaptureBase, move_from_null_to_F)
{
ProblemPtr problem = Problem::create("PO", 2);
auto F = std::make_shared<FrameBase>(0.0, nullptr); // dummy F object
auto C = std::make_shared<CaptureBase>("Dummy", 0.0);
ASSERT_DEATH(C->move(F), "");
}
int main(int argc, char **argv)
{
testing::InitGoogleTest(&argc, argv);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment