diff options
author | Michael Stahl <mstahl@redhat.com> | 2015-05-09 00:06:40 +0200 |
---|---|---|
committer | Michael Stahl <mstahl@redhat.com> | 2015-05-09 11:02:28 +0200 |
commit | d60db2401198421d8b69707e49113c89a0ea1616 (patch) | |
tree | d49556b7ae25308a181c94ee90fd4d3bb0e57867 | |
parent | 94be2168635e5305f3dfa3b1baf7f97d85ab026c (diff) |
sw: add assertions to check invariants of frame anchoring
Change-Id: Iddb5936c088dfba0245a0d921c7122a0587bdc9b
-rw-r--r-- | sw/source/core/doc/DocumentRedlineManager.cxx | 4 | ||||
-rw-r--r-- | sw/source/core/layout/atrfrm.cxx | 61 |
2 files changed, 65 insertions, 0 deletions
diff --git a/sw/source/core/doc/DocumentRedlineManager.cxx b/sw/source/core/doc/DocumentRedlineManager.cxx index 5659a96b40d0..76e5fec3b412 100644 --- a/sw/source/core/doc/DocumentRedlineManager.cxx +++ b/sw/source/core/doc/DocumentRedlineManager.cxx @@ -598,6 +598,8 @@ RedlineMode_t DocumentRedlineManager::GetRedlineMode() const return meRedlineMode; } +void CheckAnchoredFlyConsistency(SwDoc const& rDoc); + void DocumentRedlineManager::SetRedlineMode( RedlineMode_t eMode ) { if( meRedlineMode != eMode ) @@ -628,6 +630,7 @@ void DocumentRedlineManager::SetRedlineMode( RedlineMode_t eMode ) break; } + CheckAnchoredFlyConsistency(m_rDoc); _CHECK_REDLINE( *this ) if (pFnc) @@ -641,6 +644,7 @@ void DocumentRedlineManager::SetRedlineMode( RedlineMode_t eMode ) mpRedlineTbl->Resort(); } + CheckAnchoredFlyConsistency(m_rDoc); _CHECK_REDLINE( *this ) m_rDoc.SetInXMLImport( bSaveInXMLImportFlag ); } diff --git a/sw/source/core/layout/atrfrm.cxx b/sw/source/core/layout/atrfrm.cxx index 335c85e96092..e78ae9b5a00f 100644 --- a/sw/source/core/layout/atrfrm.cxx +++ b/sw/source/core/layout/atrfrm.cxx @@ -3487,4 +3487,65 @@ bool IsFlyFrmFmtInHeader(const SwFrmFmt& rFmt) return false; } +namespace sw { + +void CheckAnchoredFlyConsistency(SwDoc const& rDoc) +{ +#if OSL_DEBUG_LEVEL > 0 + SwNodes const& rNodes(rDoc.GetNodes()); + sal_uLong const count(rNodes.Count()); + for (sal_uLong i = 0; i != count; ++i) + { + SwNode const*const pNode(rNodes[i]); + std::vector<SwFrmFmt*> const*const pFlys(pNode->GetAnchoredFlys()); + if (pFlys) + { + for (auto it = pFlys->begin(); it != pFlys->end(); ++it) + { + SwFmtAnchor const& rAnchor((**it).GetAnchor(false)); + assert(&rAnchor.GetCntntAnchor()->nNode.GetNode() == pNode); + } + } + } + SwFrmFmts const*const pSpzFrmFmts(rDoc.GetSpzFrmFmts()); + if (pSpzFrmFmts) + { + for (auto it = pSpzFrmFmts->begin(); it != pSpzFrmFmts->end(); ++it) + { + SwFmtAnchor const& rAnchor((**it).GetAnchor(false)); + if (FLY_AT_PAGE == rAnchor.GetAnchorId()) + { + assert(!rAnchor.GetCntntAnchor()); + } + else + { + SwNode & rNode(rAnchor.GetCntntAnchor()->nNode.GetNode()); + std::vector<SwFrmFmt*> const*const pFlys(rNode.GetAnchoredFlys()); + assert(std::find(pFlys->begin(), pFlys->end(), *it) != pFlys->end()); + switch (rAnchor.GetAnchorId()) + { + case FLY_AT_FLY: + assert(rNode.IsStartNode()); + break; + case FLY_AT_PARA: + assert(rNode.IsTxtNode() || rNode.IsTableNode()); + break; + case FLY_AS_CHAR: + case FLY_AT_CHAR: + assert(rNode.IsTxtNode()); + break; + default: + assert(false); + break; + } + } + } + } +#else + (void) rDoc; +#endif +} + +} // namespace sw + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |