1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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/.
10 #include <test/unoapixml_test.hxx>
12 #include <com/sun/star/beans/XPropertySet.hpp>
13 #include <com/sun/star/qa/XDumper.hpp>
15 #include <test/xmldocptr.hxx>
17 using namespace com::sun::star
;
21 /// Tests for writerfilter/source/dmapper/SettingsTable.cxx.
22 class Test
: public UnoApiXmlTest
26 : UnoApiXmlTest("/writerfilter/qa/cppunittests/dmapper/data/")
31 CPPUNIT_TEST_FIXTURE(Test
, testDoNotBreakWrappedTables
)
33 // Given a document with <w:doNotBreakWrappedTables>:
34 // When importing that document:
35 loadFromFile(u
"do-not-break-wrapped-tables.docx");
37 // Then make sure that the matching compat flag is set:
38 uno::Reference
<lang::XMultiServiceFactory
> xDocument(mxComponent
, uno::UNO_QUERY
);
39 uno::Reference
<beans::XPropertySet
> xSettings(
40 xDocument
->createInstance("com.sun.star.document.Settings"), uno::UNO_QUERY
);
41 bool bDoNotBreakWrappedTables
{};
42 xSettings
->getPropertyValue("DoNotBreakWrappedTables") >>= bDoNotBreakWrappedTables
;
43 // Without the accompanying fix in place, this test would have failed, the compat flag was not
45 CPPUNIT_ASSERT(bDoNotBreakWrappedTables
);
48 CPPUNIT_TEST_FIXTURE(Test
, testAllowTextAfterFloatingTableBreak
)
50 // Given a document with <w:compatSetting w:name="allowTextAfterFloatingTableBreak">:
51 // When importing that document:
52 loadFromFile(u
"floattable-wrap-on-all-pages.docx");
54 // Then make sure that the matching compat flag is set:
55 uno::Reference
<lang::XMultiServiceFactory
> xDocument(mxComponent
, uno::UNO_QUERY
);
56 uno::Reference
<beans::XPropertySet
> xSettings(
57 xDocument
->createInstance("com.sun.star.document.Settings"), uno::UNO_QUERY
);
58 bool bAllowTextAfterFloatingTableBreak
{};
59 xSettings
->getPropertyValue("AllowTextAfterFloatingTableBreak")
60 >>= bAllowTextAfterFloatingTableBreak
;
61 // Without the accompanying fix in place, this test would have failed, the compat flag was not
63 CPPUNIT_ASSERT(bAllowTextAfterFloatingTableBreak
);
66 CPPUNIT_TEST_FIXTURE(Test
, testAddVerticalFrameOffsetsRTF
)
68 // Given a document with a floating table, immediately followed by an inline table:
69 // When importing that document:
70 loadFromFile(u
"floattable-vertical-frame-offset.rtf");
72 // Then make sure the floating and the inline tables don't overlap:
73 uno::Reference
<frame::XModel
> xModel(mxComponent
, uno::UNO_QUERY
);
74 css::uno::Reference
<qa::XDumper
> xDumper(xModel
->getCurrentController(), uno::UNO_QUERY
);
75 OString aDump
= xDumper
->dump("layout").toUtf8();
76 auto pCharBuffer
= reinterpret_cast<const xmlChar
*>(aDump
.getStr());
77 xmlDocUniquePtr
pXmlDoc(xmlParseDoc(pCharBuffer
));
78 sal_Int32 nFlyBottom
= getXPath(pXmlDoc
, "//fly/infos/bounds"_ostr
, "bottom"_ostr
).toInt32();
79 sal_Int32 nTableFrameTop
80 = getXPath(pXmlDoc
, "//body/tab/infos/bounds"_ostr
, "top"_ostr
).toInt32();
81 sal_Int32 nTableTopMargin
82 = getXPath(pXmlDoc
, "//body/tab/infos/prtBounds"_ostr
, "top"_ostr
).toInt32();
83 sal_Int32 nTableTop
= nTableFrameTop
+ nTableTopMargin
;
84 // Without the accompanying fix in place, this test would have failed with:
85 // - Expected greater than: 2747
87 // i.e. table top should be ~2748, but was less, leading to an overlap.
88 CPPUNIT_ASSERT_GREATER(nFlyBottom
, nTableTop
);
92 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */