Debian Codegraph @

sw/qa/writerfilter/dmapper/SettingsTable.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 <test/unoapixml_test.hxx>
11
12 #include <com/sun/star/beans/XPropertySet.hpp>
13 #include <com/sun/star/qa/XDumper.hpp>
14 #include <com/sun/star/text/XTextDocument.hpp>
15
16 #include <test/xmldocptr.hxx>
17
18 using namespace com::sun::star;
19
20 namespace
21 {
22 /// Tests for sw/source/writerfilter/dmapper/SettingsTable.cxx.
23 class Test : public UnoApiXmlTest
24 {
25 public:
26 Test()
27 : UnoApiXmlTest(u"/sw/qa/writerfilter/dmapper/data/"_ustr)
28 {
29 }
30 };
31
32 CPPUNIT_TEST_FIXTURE(Test, testDoNotBreakWrappedTables)
33 {
34 // Given a document with <w:doNotBreakWrappedTables>:
35 // When importing that document:
36 loadFromFile(u"do-not-break-wrapped-tables.docx");
37
38 // Then make sure that the matching compat flag is set:
39 uno::Reference<lang::XMultiServiceFactory> xDocument(mxComponent, uno::UNO_QUERY);
40 uno::Reference<beans::XPropertySet> xSettings(
41 xDocument->createInstance(u"com.sun.star.document.Settings"_ustr), uno::UNO_QUERY);
42 bool bDoNotBreakWrappedTables{};
43 xSettings->getPropertyValue(u"DoNotBreakWrappedTables"_ustr) >>= bDoNotBreakWrappedTables;
44 // Without the accompanying fix in place, this test would have failed, the compat flag was not
45 // set.
46 CPPUNIT_ASSERT(bDoNotBreakWrappedTables);
47 }
48
49 CPPUNIT_TEST_FIXTURE(Test, testAllowTextAfterFloatingTableBreak)
50 {
51 // Given a document with <w:compatSetting w:name="allowTextAfterFloatingTableBreak">:
52 // When importing that document:
53 loadFromFile(u"floattable-wrap-on-all-pages.docx");
54
55 // Then make sure that the matching compat flag is set:
56 uno::Reference<lang::XMultiServiceFactory> xDocument(mxComponent, uno::UNO_QUERY);
57 uno::Reference<beans::XPropertySet> xSettings(
58 xDocument->createInstance(u"com.sun.star.document.Settings"_ustr), uno::UNO_QUERY);
59 bool bAllowTextAfterFloatingTableBreak{};
60 xSettings->getPropertyValue(u"AllowTextAfterFloatingTableBreak"_ustr)
61 >>= bAllowTextAfterFloatingTableBreak;
62 // Without the accompanying fix in place, this test would have failed, the compat flag was not
63 // set.
64 CPPUNIT_ASSERT(bAllowTextAfterFloatingTableBreak);
65 }
66
67 CPPUNIT_TEST_FIXTURE(Test, testAddVerticalFrameOffsetsRTF)
68 {
69 // Given a document with a floating table, immediately followed by an inline table:
70 // When importing that document:
71 loadFromFile(u"floattable-vertical-frame-offset.rtf");
72
73 // Then make sure the floating and the inline tables don't overlap:
74 uno::Reference<frame::XModel> xModel(mxComponent, uno::UNO_QUERY);
75 css::uno::Reference<qa::XDumper> xDumper(xModel->getCurrentController(), uno::UNO_QUERY);
76 OString aDump = xDumper->dump(u"layout"_ustr).toUtf8();
77 auto pCharBuffer = reinterpret_cast<const xmlChar*>(aDump.getStr());
78 xmlDocUniquePtr pXmlDoc(xmlParseDoc(pCharBuffer));
79 sal_Int32 nFlyBottom = getXPath(pXmlDoc, "//fly/infos/bounds", "bottom").toInt32();
80 sal_Int32 nTableFrameTop = getXPath(pXmlDoc, "//body/tab/infos/bounds", "top").toInt32();
81 sal_Int32 nTableTopMargin = getXPath(pXmlDoc, "//body/tab/infos/prtBounds", "top").toInt32();
82 sal_Int32 nTableTop = nTableFrameTop + nTableTopMargin;
83 // Without the accompanying fix in place, this test would have failed with:
84 // - Expected greater than: 2747
85 // - Actual : 1449
86 // i.e. table top should be ~2748, but was less, leading to an overlap.
87 CPPUNIT_ASSERT_GREATER(nFlyBottom, nTableTop);
88 }
89
90 CPPUNIT_TEST_FIXTURE(Test, testEndnoteAtSectionEnd)
91 {
92 // Given a document with at-section-end endnotes enabled:
93 loadFromFile(u"endnote-at-section-end.docx");
94
95 // Go to the second paragraph, which is inside Word's second section:
96 uno::Reference<text::XTextDocument> xTextDocument(mxComponent, uno::UNO_QUERY);
97 uno::Reference<container::XEnumerationAccess> xParaEnumAccess(xTextDocument->getText(),
98 uno::UNO_QUERY);
99 uno::Reference<container::XEnumeration> xParaEnum = xParaEnumAccess->createEnumeration();
100 xParaEnum->nextElement();
101 uno::Reference<beans::XPropertySet> xPara(xParaEnum->nextElement(), uno::UNO_QUERY);
102 uno::Reference<beans::XPropertySet> xSection;
103 xPara->getPropertyValue(u"TextSection"_ustr) >>= xSection;
104 bool bEndnoteIsCollectAtTextEnd = false;
105 xSection->getPropertyValue(u"EndnoteIsCollectAtTextEnd"_ustr) >>= bEndnoteIsCollectAtTextEnd;
106 // Without the accompanying fix in place, this test would have failed, endnotes were always at
107 // document end.
108 CPPUNIT_ASSERT(bEndnoteIsCollectAtTextEnd);
109 }
110 }
111
112 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */