Debian Codegraph @

sw/qa/uibase/shells/textfld.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
14 #include <wrtsh.hxx>
15 #include <docsh.hxx>
16 #include <ftnidx.hxx>
17 #include <txtftn.hxx>
18
19 namespace
20 {
21 /// Covers sw/source/uibase/shells/textfld.cxx fixes.
22 class Test : public SwModelTestBase
23 {
24 public:
25 Test()
26 : SwModelTestBase(u"/sw/qa/uibase/shells/data/"_ustr)
27 {
28 }
29 };
30 }
31
32 CPPUNIT_TEST_FIXTURE(Test, testInsertRefmarkFootnote)
33 {
34 // Given an empty document:
35 createSwDoc();
36
37 // When inserting a refmark inside a footnote:
38 uno::Sequence<css::beans::PropertyValue> aArgs = {
39 comphelper::makePropertyValue(u"TypeName"_ustr, uno::Any(u"SetRef"_ustr)),
40 comphelper::makePropertyValue(u"Name"_ustr, uno::Any(u"myref"_ustr)),
41 comphelper::makePropertyValue(u"Content"_ustr, uno::Any(u"content"_ustr)),
42 comphelper::makePropertyValue(u"Wrapper"_ustr, uno::Any(u"Footnote"_ustr)),
43 };
44 dispatchCommand(mxComponent, u".uno:InsertField"_ustr, aArgs);
45
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(u"content"_ustr, rFormatNote.GetFootnoteText(*pWrtShell->GetLayout()));
59 }
60
61 CPPUNIT_TEST_FIXTURE(Test, testInsertRefmarkEndnote)
62 {
63 // Given an empty document:
64 createSwDoc();
65
66 // When inserting a refmark inside an endnote:
67 uno::Sequence<css::beans::PropertyValue> aArgs = {
68 comphelper::makePropertyValue(u"TypeName"_ustr, uno::Any(u"SetRef"_ustr)),
69 comphelper::makePropertyValue(u"Name"_ustr, uno::Any(u"myref"_ustr)),
70 comphelper::makePropertyValue(u"Content"_ustr, uno::Any(u"content"_ustr)),
71 comphelper::makePropertyValue(u"Wrapper"_ustr, uno::Any(u"Endnote"_ustr)),
72 };
73 dispatchCommand(mxComponent, u".uno:InsertField"_ustr, aArgs);
74
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(u"content"_ustr, rNote.GetFootnoteText(*pWrtShell->GetLayout()));
88 }
89
90 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */