Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / sw / qa / uibase / shells / textfld.cxx
blob6f9fa0c1c2f6ef2472aafd5004219fed8f27ca21
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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 */
10 #include <swmodeltestbase.hxx>
12 #include <comphelper/propertyvalue.hxx>
14 #include <wrtsh.hxx>
15 #include <docsh.hxx>
16 #include <ftnidx.hxx>
17 #include <txtftn.hxx>
19 namespace
21 /// Covers sw/source/uibase/shells/textfld.cxx fixes.
22 class Test : public SwModelTestBase
24 public:
25 Test()
26 : SwModelTestBase("/sw/qa/uibase/shells/data/")
32 CPPUNIT_TEST_FIXTURE(Test, testInsertRefmarkFootnote)
34 // Given an empty document:
35 createSwDoc();
37 // When inserting a refmark inside a footnote:
38 uno::Sequence<css::beans::PropertyValue> aArgs = {
39 comphelper::makePropertyValue("TypeName", uno::Any(OUString("SetRef"))),
40 comphelper::makePropertyValue("Name", uno::Any(OUString("myref"))),
41 comphelper::makePropertyValue("Content", uno::Any(OUString("content"))),
42 comphelper::makePropertyValue("Wrapper", uno::Any(OUString("Footnote"))),
44 dispatchCommand(mxComponent, ".uno:InsertField", aArgs);
46 // Then make sure that the note body contains the refmark:
47 SwDoc* pDoc = getSwDoc();
48 SwFootnoteIdxs& rNotes = pDoc->GetFootnoteIdxs();
49 // Without the accompanying fix in place, this test would have failed with:
50 // - Expected: 1
51 // - Actual : 0
52 // i.e. no note was inserted.
53 CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), rNotes.size());
54 SwTextFootnote* pNote = rNotes[0];
55 const SwFormatFootnote& rFormatNote = pNote->GetFootnote();
56 CPPUNIT_ASSERT(!rFormatNote.IsEndNote());
57 SwWrtShell* pWrtShell = getSwDocShell()->GetWrtShell();
58 CPPUNIT_ASSERT_EQUAL(OUString("content"), rFormatNote.GetFootnoteText(*pWrtShell->GetLayout()));
61 CPPUNIT_TEST_FIXTURE(Test, testInsertRefmarkEndnote)
63 // Given an empty document:
64 createSwDoc();
66 // When inserting a refmark inside an endnote:
67 uno::Sequence<css::beans::PropertyValue> aArgs = {
68 comphelper::makePropertyValue("TypeName", uno::Any(OUString("SetRef"))),
69 comphelper::makePropertyValue("Name", uno::Any(OUString("myref"))),
70 comphelper::makePropertyValue("Content", uno::Any(OUString("content"))),
71 comphelper::makePropertyValue("Wrapper", uno::Any(OUString("Endnote"))),
73 dispatchCommand(mxComponent, ".uno:InsertField", aArgs);
75 // Then make sure that the note body contains the refmark:
76 SwDoc* pDoc = getSwDoc();
77 SwFootnoteIdxs& rNotes = pDoc->GetFootnoteIdxs();
78 // Without the accompanying fix in place, this test would have failed with:
79 // - Expected: 1
80 // - Actual : 0
81 // i.e. no endnote was inserted.
82 CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), rNotes.size());
83 SwTextFootnote* pNote = rNotes[0];
84 const SwFormatFootnote& rNote = pNote->GetFootnote();
85 CPPUNIT_ASSERT(rNote.IsEndNote());
86 SwWrtShell* pWrtShell = getSwDocShell()->GetWrtShell();
87 CPPUNIT_ASSERT_EQUAL(OUString("content"), rNote.GetFootnoteText(*pWrtShell->GetLayout()));
90 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */