diff options
author | Stephan Bergmann <sbergman@redhat.com> | 2017-06-16 09:58:13 +0200 |
---|---|---|
committer | Stephan Bergmann <sbergman@redhat.com> | 2017-06-16 17:28:41 +0200 |
commit | 13bb5a4b09f5b2ad19dad1b55f45d0fe2b2fb908 (patch) | |
tree | d38ad18688a292ff6ccdfaa7c51080197ec95934 /sw/qa | |
parent | f83d8ae84584c0967e2346566d21d65d6d7a432f (diff) |
Make SfxItemSet ranges correct by construction
This is a follow-up to 45a7f5b62d0b1b21763c1c94255ef2309ea4280b "Keep WID ranges
sorted, and join adjacent ones". While SfxItemSet::MergeRange relies on the
m_pWhichRanges being sorted (and, under DBG_UTIL, asserts if they are not), the
various SfxItemSet constructors curiously only check (via assert or DBG_ASSERT)
that each individual range has an upper bound not smaller than its lower bound.
Arguably, all SfxItemSet instances should fulfill the stronger guarantees
required and checked by MergeRange.
And in many cases the ranges are statically known, so that the checking can
happen at compile time. Therefore, replace the two SfxItemSet ctors taking
explicit ranges with two other ctors that actually do proper checking. The
(templated) overload taking an svl::Items struct should be used in all cases
where the range values are statically known at compile time, while the overload
taking a std::initializer_list<Pair> is for the remaining cases (that can only
do runtime checking via assert). Most of those latter cases are simple cases
with a single range covering a single item, but a few are more complex.
(At least some of the uses of the existing SfxItemSet overload taking a
const sal_uInt16* pWhichPairTable
can probably also be strengthened, but that is left for another day.)
This commit is the first in a series of two. Apart from the manual changes to
compilerplugins/clang/store/sfxitemsetrewrite.cxx, include/svl/itemset.hxx, and
svl/source/items/itemset.cxx, it only consists of automatic rewriting of the
relevant SfxItemSet ctor calls (plus a few required manual fixes, see next).
But it does not yet check that the individual ranges are properly sorted (see
the TODO in svl::detail::validGap). That check will be enabled, and the ensuing
manual fixes will be made in a follow-up commit, to reduce the likelyhood of
accidents.
There were three cases of necessary manual intervention:
* sw/source/core/unocore/unostyle.cxx uses eAtr of enum type RES_FRMATR in
braced-init-list syntax now, so needs explicit narrowing conversion to
sal_uInt16.
* In sw/source/uibase/uiview/formatclipboard.cxx, the trailiing comma in the
definition of macro FORMAT_PAINTBRUSH_FRAME_IDS needed to be removed manually.
* In svx/source/svdraw/svdoashp.cxx, svx/source/svdraw/svdotext.cxx,
sw/source/uibase/app/docstyle.cxx, sw/source/uibase/shells/frmsh.cxx,
sw/source/uibase/shells/grfsh.cxx, and sw/source/uibase/shells/textsh1.cxx,
some comments had to be put back (see "TODO: the replaced range can contain
relevant comments" in compilerplugins/clang/store/sfxitemsetrewrite.cxx).
A few uses of the variadic form erroneously used nullptr instead of 0 for
termination. But this should have been harmless even if promoted std::nullptr_t
is larger than promoted sal_uInt16, assuming that the part of the nullptr value
that was interpreted as sal_uInt16/promoted int was all-zero bits. Similarly,
some uses made the harmless error of using 0L instead of 0.
Change-Id: I2afea97282803cb311b9321a99bb627520ef5e35
Reviewed-on: https://gerrit.libreoffice.org/38861
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
Tested-by: Stephan Bergmann <sbergman@redhat.com>
Diffstat (limited to 'sw/qa')
-rw-r--r-- | sw/qa/core/uwriter.cxx | 2 | ||||
-rw-r--r-- | sw/qa/extras/tiledrendering/tiledrendering.cxx | 14 | ||||
-rw-r--r-- | sw/qa/extras/uiwriter/uiwriter.cxx | 16 | ||||
-rw-r--r-- | sw/qa/extras/ww8export/ww8export.cxx | 2 |
4 files changed, 17 insertions, 17 deletions
diff --git a/sw/qa/core/uwriter.cxx b/sw/qa/core/uwriter.cxx index e0ccaaeb778b..e816a91f0b30 100644 --- a/sw/qa/core/uwriter.cxx +++ b/sw/qa/core/uwriter.cxx @@ -970,7 +970,7 @@ void SwDocTest::testGraphicAnchorDeletion() aPaM.GetPoint()->nContent.Assign(aPaM.GetContentNode(), RTL_CONSTASCII_LENGTH("graphic anchor>>")); //Insert a graphic at X of >>X<< in paragraph 2 - SfxItemSet aFlySet(m_pDoc->GetAttrPool(), RES_FRMATR_BEGIN, RES_FRMATR_END-1); + SfxItemSet aFlySet(m_pDoc->GetAttrPool(), svl::Items<RES_FRMATR_BEGIN, RES_FRMATR_END-1>{}); SwFormatAnchor aAnchor(RndStdIds::FLY_AS_CHAR); aAnchor.SetAnchor(aPaM.GetPoint()); aFlySet.Put(aAnchor); diff --git a/sw/qa/extras/tiledrendering/tiledrendering.cxx b/sw/qa/extras/tiledrendering/tiledrendering.cxx index ecd84826233f..e719a368558e 100644 --- a/sw/qa/extras/tiledrendering/tiledrendering.cxx +++ b/sw/qa/extras/tiledrendering/tiledrendering.cxx @@ -1383,7 +1383,7 @@ void SwTiledRenderingTest::testTrackChangesCallback() CPPUNIT_ASSERT_EQUAL(-1, m_nTrackedChangeIndex); pWrtShell->Left(CRSR_SKIP_CHARS, /*bSelect=*/false, 1, /*bBasicCall=*/false); - SfxItemSet aSet(pWrtShell->GetDoc()->GetAttrPool(), FN_REDLINE_ACCEPT_DIRECT, FN_REDLINE_ACCEPT_DIRECT); + SfxItemSet aSet(pWrtShell->GetDoc()->GetAttrPool(), svl::Items<FN_REDLINE_ACCEPT_DIRECT, FN_REDLINE_ACCEPT_DIRECT>{}); SfxVoidItem aItem(FN_REDLINE_ACCEPT_DIRECT); aSet.Put(aItem); pWrtShell->GetView().GetState(aSet); @@ -1730,8 +1730,8 @@ namespace { void checkUndoRepairStates(SwXTextDocument* pXTextDocument, SwView* pView1, SwView* pView2) { - SfxItemSet aItemSet1(pXTextDocument->GetDocShell()->GetDoc()->GetAttrPool(), SID_UNDO, SID_UNDO); - SfxItemSet aItemSet2(pXTextDocument->GetDocShell()->GetDoc()->GetAttrPool(), SID_UNDO, SID_UNDO); + SfxItemSet aItemSet1(pXTextDocument->GetDocShell()->GetDoc()->GetAttrPool(), svl::Items<SID_UNDO, SID_UNDO>{}); + SfxItemSet aItemSet2(pXTextDocument->GetDocShell()->GetDoc()->GetAttrPool(), svl::Items<SID_UNDO, SID_UNDO>{}); // first view, undo enabled pView1->GetState(aItemSet1); CPPUNIT_ASSERT_EQUAL(SfxItemState::SET, aItemSet1.GetItemState(SID_UNDO)); @@ -1764,8 +1764,8 @@ void SwTiledRenderingTest::testDisableUndoRepair() int nView2 = SfxLokHelper::getView(); { - SfxItemSet aItemSet1(pXTextDocument->GetDocShell()->GetDoc()->GetAttrPool(), SID_UNDO, SID_UNDO); - SfxItemSet aItemSet2(pXTextDocument->GetDocShell()->GetDoc()->GetAttrPool(), SID_UNDO, SID_UNDO); + SfxItemSet aItemSet1(pXTextDocument->GetDocShell()->GetDoc()->GetAttrPool(), svl::Items<SID_UNDO, SID_UNDO>{}); + SfxItemSet aItemSet2(pXTextDocument->GetDocShell()->GetDoc()->GetAttrPool(), svl::Items<SID_UNDO, SID_UNDO>{}); pView1->GetState(aItemSet1); CPPUNIT_ASSERT_EQUAL(SfxItemState::DISABLED, aItemSet1.GetItemState(SID_UNDO)); pView2->GetState(aItemSet2); @@ -1785,8 +1785,8 @@ void SwTiledRenderingTest::testDisableUndoRepair() pXTextDocument->postKeyEvent(LOK_KEYEVENT_KEYUP, 'u', 0); Scheduler::ProcessEventsToIdle(); { - SfxItemSet aItemSet1(pXTextDocument->GetDocShell()->GetDoc()->GetAttrPool(), SID_UNDO, SID_UNDO); - SfxItemSet aItemSet2(pXTextDocument->GetDocShell()->GetDoc()->GetAttrPool(), SID_UNDO, SID_UNDO); + SfxItemSet aItemSet1(pXTextDocument->GetDocShell()->GetDoc()->GetAttrPool(), svl::Items<SID_UNDO, SID_UNDO>{}); + SfxItemSet aItemSet2(pXTextDocument->GetDocShell()->GetDoc()->GetAttrPool(), svl::Items<SID_UNDO, SID_UNDO>{}); // second view, undo enabled pView2->GetState(aItemSet2); CPPUNIT_ASSERT_EQUAL(SfxItemState::SET, aItemSet2.GetItemState(SID_UNDO)); diff --git a/sw/qa/extras/uiwriter/uiwriter.cxx b/sw/qa/extras/uiwriter/uiwriter.cxx index 7ef2dabaf0d4..e1d73952b9e5 100644 --- a/sw/qa/extras/uiwriter/uiwriter.cxx +++ b/sw/qa/extras/uiwriter/uiwriter.cxx @@ -1004,7 +1004,7 @@ void SwUiWriterTest::testCp1000071() // Change the document layout to be 2 columns, and then undo. pWrtShell->SelAll(); SwSectionData section(CONTENT_SECTION, pWrtShell->GetUniqueSectionName()); - SfxItemSet set( pDoc->GetDocShell()->GetPool(), RES_COL, RES_COL, 0 ); + SfxItemSet set( pDoc->GetDocShell()->GetPool(), svl::Items<RES_COL, RES_COL>{} ); SwFormatCol col; col.Init( 2, 0, 10000 ); set.Put( col ); @@ -2078,7 +2078,7 @@ void SwUiWriterTest::testTdf72788() //Apply a *Bold* attribute to selection SvxWeightItem aWeightItem(WEIGHT_BOLD, RES_CHRATR_WEIGHT); rIDCO.InsertPoolItem(*pCursor, aWeightItem); - SfxItemSet aSet( pDoc->GetAttrPool(), RES_CHRATR_WEIGHT, RES_CHRATR_WEIGHT); + SfxItemSet aSet( pDoc->GetAttrPool(), svl::Items<RES_CHRATR_WEIGHT, RES_CHRATR_WEIGHT>{}); //Add selected text's attributes to aSet pCursor->GetNode().GetTextNode()->GetAttr(aSet, 5, 12); SfxPoolItem const * pPoolItem = aSet.GetItem(RES_CHRATR_WEIGHT); @@ -3225,8 +3225,8 @@ void SwUiWriterTest::testUndoDelAsCharTdf107512() sw::UndoManager & rUndoManager(pDoc->GetUndoManager()); IDocumentContentOperations & rIDCO(pDoc->getIDocumentContentOperations()); SwCursorShell * pShell(pDoc->GetEditShell()); - SfxItemSet frameSet(pDoc->GetAttrPool(), RES_FRMATR_BEGIN, RES_FRMATR_END-1); - SfxItemSet grfSet(pDoc->GetAttrPool(), RES_GRFATR_BEGIN, RES_GRFATR_END-1); + SfxItemSet frameSet(pDoc->GetAttrPool(), svl::Items<RES_FRMATR_BEGIN, RES_FRMATR_END-1>{}); + SfxItemSet grfSet(pDoc->GetAttrPool(), svl::Items<RES_GRFATR_BEGIN, RES_GRFATR_END-1>{}); rIDCO.InsertString(*pShell->GetCursor(), "foo"); pShell->ClearMark(); SwFormatAnchor anchor(RndStdIds::FLY_AS_CHAR); @@ -3245,7 +3245,7 @@ void SwUiWriterTest::testUndoDelAsCharTdf107512() CPPUNIT_ASSERT(pShell->GetCursor()->GetNode().GetTextNode()->GetTextAttrForCharAt(4, RES_TXTATR_FLYCNT)); CPPUNIT_ASSERT_EQUAL(OUString(OUStringLiteral1(CH_TXTATR_BREAKWORD) + u"foo" + OUStringLiteral1(CH_TXTATR_BREAKWORD)), pShell->GetCursor()->GetNode().GetTextNode()->GetText()); SfxPoolItem const* pItem; - SfxItemSet query(pDoc->GetAttrPool(), RES_CHRATR_HIDDEN, RES_CHRATR_HIDDEN); + SfxItemSet query(pDoc->GetAttrPool(), svl::Items<RES_CHRATR_HIDDEN, RES_CHRATR_HIDDEN>{}); pShell->GetCursor()->GetNode().GetTextNode()->GetAttr(query, 1, 4); CPPUNIT_ASSERT_EQUAL(SfxItemState::SET, query.GetItemState(RES_CHRATR_HIDDEN, false, &pItem)); CPPUNIT_ASSERT(static_cast<SvxCharHiddenItem const*>(pItem)->GetValue()); @@ -3358,7 +3358,7 @@ void SwUiWriterTest::testUndoCharAttribute() // Apply a "Bold" attribute to selection SvxWeightItem aWeightItem(WEIGHT_BOLD, RES_CHRATR_WEIGHT); rIDCO.InsertPoolItem(*pCursor, aWeightItem); - SfxItemSet aSet( pDoc->GetAttrPool(), RES_CHRATR_WEIGHT, RES_CHRATR_WEIGHT); + SfxItemSet aSet( pDoc->GetAttrPool(), svl::Items<RES_CHRATR_WEIGHT, RES_CHRATR_WEIGHT>{}); // Adds selected text's attributes to aSet pCursor->GetNode().GetTextNode()->GetAttr(aSet, 10, 19); SfxPoolItem const * pPoolItem = aSet.GetItem(RES_CHRATR_WEIGHT); @@ -3379,8 +3379,8 @@ void SwUiWriterTest::testUndoDelAsChar() sw::UndoManager & rUndoManager(pDoc->GetUndoManager()); IDocumentContentOperations & rIDCO(pDoc->getIDocumentContentOperations()); SwCursorShell * pShell(pDoc->GetEditShell()); - SfxItemSet frameSet(pDoc->GetAttrPool(), RES_FRMATR_BEGIN, RES_FRMATR_END-1); - SfxItemSet grfSet(pDoc->GetAttrPool(), RES_GRFATR_BEGIN, RES_GRFATR_END-1); + SfxItemSet frameSet(pDoc->GetAttrPool(), svl::Items<RES_FRMATR_BEGIN, RES_FRMATR_END-1>{}); + SfxItemSet grfSet(pDoc->GetAttrPool(), svl::Items<RES_GRFATR_BEGIN, RES_GRFATR_END-1>{}); SwFormatAnchor anchor(RndStdIds::FLY_AS_CHAR); frameSet.Put(anchor); GraphicObject grf; diff --git a/sw/qa/extras/ww8export/ww8export.cxx b/sw/qa/extras/ww8export/ww8export.cxx index 2af0b8fde045..003c12a6e0d8 100644 --- a/sw/qa/extras/ww8export/ww8export.cxx +++ b/sw/qa/extras/ww8export/ww8export.cxx @@ -129,7 +129,7 @@ protected: // emulate the behavior from tdf#94386 - insert an envelope to the // document - SfxItemSet aSet(pWrtShell->GetView().GetCurShell()->GetPool(), FN_ENVELOP, FN_ENVELOP); + SfxItemSet aSet(pWrtShell->GetView().GetCurShell()->GetPool(), svl::Items<FN_ENVELOP, FN_ENVELOP>{}); aSet.Put(SwEnvItem()); SfxRequest aRequest(FN_ENVELOP, SfxCallMode::SYNCHRON, aSet); SW_MOD()->ExecOther(aRequest); |