From 865060e2e910f0e7d2e447f96808e6cf628e4dc0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9a=20Saviot?= Date: Fri, 19 Jan 2018 09:58:59 +0100 Subject: [PATCH] [poincare] Add asserts in removePointedChildAtIndexAndMoveCursor. Change-Id: Ifc49b79f18ad53a96a4675d1c6edad69e1c6258f --- poincare/src/layout/conjugate_layout.cpp | 1 + poincare/src/layout/dynamic_layout_hierarchy.cpp | 2 +- poincare/src/layout/expression_layout.cpp | 1 + poincare/src/layout/matrix_layout.cpp | 1 + 4 files changed, 4 insertions(+), 1 deletion(-) diff --git a/poincare/src/layout/conjugate_layout.cpp b/poincare/src/layout/conjugate_layout.cpp index 15e90362d..e9c3fda59 100644 --- a/poincare/src/layout/conjugate_layout.cpp +++ b/poincare/src/layout/conjugate_layout.cpp @@ -95,6 +95,7 @@ void ConjugateLayout::replaceChildAndMoveCursor(const ExpressionLayout * oldChil void ConjugateLayout::removePointedChildAtIndexAndMoveCursor(int index, bool deleteAfterRemoval, ExpressionLayoutCursor * cursor) { assert(index >= 0 && index < numberOfChildren()); + assert((cursor->pointedExpressionLayout() == child(index)) || (cursor->pointedExpressionLayout()->hasAncestor(child(index)))); replaceChildAndMoveCursor(child(index), new EmptyVisibleLayout(), deleteAfterRemoval, cursor); } diff --git a/poincare/src/layout/dynamic_layout_hierarchy.cpp b/poincare/src/layout/dynamic_layout_hierarchy.cpp index 8a54de8b3..3ed6dd802 100644 --- a/poincare/src/layout/dynamic_layout_hierarchy.cpp +++ b/poincare/src/layout/dynamic_layout_hierarchy.cpp @@ -116,7 +116,7 @@ void DynamicLayoutHierarchy::removeChildAtIndex(int index, bool deleteAfterRemov void DynamicLayoutHierarchy::removePointedChildAtIndexAndMoveCursor(int index, bool deleteAfterRemoval, ExpressionLayoutCursor * cursor) { assert(index >= 0 && index < numberOfChildren()); - assert(cursor->pointedExpressionLayout() == child(index)); + assert((cursor->pointedExpressionLayout() == child(index)) || (cursor->pointedExpressionLayout()->hasAncestor(child(index)))); if (numberOfChildren() == 1) { if (m_parent) { if (!deleteAfterRemoval) { diff --git a/poincare/src/layout/expression_layout.cpp b/poincare/src/layout/expression_layout.cpp index 936c7c9fd..9faf5b7e0 100644 --- a/poincare/src/layout/expression_layout.cpp +++ b/poincare/src/layout/expression_layout.cpp @@ -205,6 +205,7 @@ void ExpressionLayout::removeChildAtIndex(int index, bool deleteAfterRemoval) { void ExpressionLayout::removePointedChildAtIndexAndMoveCursor(int index, bool deleteAfterRemoval, ExpressionLayoutCursor * cursor) { assert(index >= 0 && index < numberOfChildren()); + assert((cursor->pointedExpressionLayout() == child(index)) || (cursor->pointedExpressionLayout()->hasAncestor(child(index)))); removeChildAtIndex(index, deleteAfterRemoval); if (index < numberOfChildren()) { cursor->setPointedExpressionLayout(editableChild(index)); diff --git a/poincare/src/layout/matrix_layout.cpp b/poincare/src/layout/matrix_layout.cpp index 753b3e7b4..273fd1d3c 100644 --- a/poincare/src/layout/matrix_layout.cpp +++ b/poincare/src/layout/matrix_layout.cpp @@ -125,6 +125,7 @@ void MatrixLayout::replaceChildAndMoveCursor(const ExpressionLayout * oldChild, void MatrixLayout::removePointedChildAtIndexAndMoveCursor(int index, bool deleteAfterRemoval, ExpressionLayoutCursor * cursor) { assert(index >= 0 && index < numberOfChildren()); + assert((cursor->pointedExpressionLayout() == child(index)) || (cursor->pointedExpressionLayout()->hasAncestor(child(index)))); replaceChildAndMoveCursor(child(index), new EmptyVisibleLayout(), deleteAfterRemoval, cursor); }