Debian Codegraph @

sw/qa/uibase/shells/textsh.cxx

raw
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 */
9
10 #include <swmodeltestbase.hxx>
11
12 #include <comphelper/propertyvalue.hxx>
13 #include <comphelper/propertysequence.hxx>
14 #include <comphelper/sequence.hxx>
15 #include <sfx2/viewfrm.hxx>
16 #include <sfx2/bindings.hxx>
17
18 #include <docary.hxx>
19 #include <docsh.hxx>
20 #include <frmmgr.hxx>
21 #include <wrtsh.hxx>
22 #include <formatflysplit.hxx>
23 #include <view.hxx>
24 #include <cmdid.h>
25
26 namespace
27 {
28 /// Covers sw/source/uibase/shells/textsh.cxx fixes.
29 class Test : public SwModelTestBase
30 {
31 public:
32 Test()
33 : SwModelTestBase(u"/sw/qa/uibase/shells/data/"_ustr)
34 {
35 }
36 };
37
38 CPPUNIT_TEST_FIXTURE(Test, testDeleteSections)
39 {
40 // Given a document with a section:
41 createSwDoc();
42 SwDoc* pDoc = getSwDoc();
43 uno::Sequence<css::beans::PropertyValue> aArgs = {
44 comphelper::makePropertyValue(u"RegionName"_ustr,
45 uno::Any(u"ZOTERO_BIBL {} CSL_BIBLIOGRAPHY RND"_ustr)),
46 comphelper::makePropertyValue(u"Content"_ustr, uno::Any(u"old content"_ustr)),
47 };
48 dispatchCommand(mxComponent, u".uno:InsertSection"_ustr, aArgs);
49 CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), pDoc->GetSections().size());
50
51 // When deleting sections:
52 std::vector<beans::PropertyValue> aArgsVec = comphelper::JsonToPropertyValues(R"json(
53 {
54 "SectionNamePrefix": {
55 "type": "string",
56 "value": "ZOTERO_BIBL"
57 }
58 }
59 )json");
60 aArgs = comphelper::containerToSequence(aArgsVec);
61 dispatchCommand(mxComponent, u".uno:DeleteSections"_ustr, aArgs);
62
63 // Then make sure that the section is deleted:
64 // Without the accompanying fix in place, this test would have failed with:
65 // - Expected: 0
66 // - Actual : 1
67 // i.e. the section was not deleted.
68 CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(0), pDoc->GetSections().size());
69 }
70
71 CPPUNIT_TEST_FIXTURE(Test, testSplitFlyFootnoteUI)
72 {
73 // Given a document with a split fly (to host a table):
74 createSwDoc();
75 SwDoc* pDoc = getSwDoc();
76 SwWrtShell* pWrtShell = getSwDocShell()->GetWrtShell();
77 SwFlyFrameAttrMgr aMgr(true, pWrtShell, Frmmgr_Type::TEXT, nullptr);
78 RndStdIds eAnchor = RndStdIds::FLY_AT_PARA;
79 pWrtShell->StartAllAction();
80 aMgr.InsertFlyFrame(eAnchor, aMgr.GetPos(), aMgr.GetSize());
81 pWrtShell->EndAllAction();
82 pWrtShell->StartAllAction();
83 sw::FrameFormats<sw::SpzFrameFormat*>& rFlys = *pDoc->GetSpzFrameFormats();
84 sw::SpzFrameFormat* pFly = rFlys[0];
85 {
86 SwAttrSet aSet(pFly->GetAttrSet());
87 aSet.Put(SwFormatFlySplit(true));
88 pDoc->SetAttr(aSet, *pFly);
89 }
90 pWrtShell->EndAllAction();
91 pWrtShell->UnSelectFrame();
92 pWrtShell->LeaveSelFrameMode();
93 pWrtShell->GetView().AttrChangedNotify(nullptr);
94 pWrtShell->MoveSection(GoCurrSection, fnSectionEnd);
95
96 // When checking if we can insert a footnote inside the split fly:
97 SwView& rView = pWrtShell->GetView();
98 std::unique_ptr<SfxPoolItem> pItem;
99 SfxItemState eState = rView.GetViewFrame().GetBindings().QueryState(FN_INSERT_FOOTNOTE, pItem);
100
101 // Then make sure that the insertion is allowed:
102 // Without the accompanying fix in place, this test would have failed with:
103 // - Expected: 32 (DEFAULT)
104 // - Actual : 1 (DISABLED)
105 // i.e. the insertion was denied.
106 CPPUNIT_ASSERT_EQUAL(SfxItemState::DEFAULT, eState);
107 }
108 }
109
110 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */