summaryrefslogtreecommitdiff
path: root/sw/qa/writerfilter/cppunittests/dmapper/SettingsTable.cxx
diff options
context:
space:
mode:
authorNoel Grandin <noelgrandin@gmail.com>2024-04-10 16:50:51 +0100
committerNoel Grandin <noel.grandin@collabora.co.uk>2024-04-18 09:16:12 +0200
commit828c1999e08c5bfad0a1d0e6e5ab07ee8bbc427e (patch)
tree65dfe08b2f389fd5b6d8a639fda2815815931b2e /sw/qa/writerfilter/cppunittests/dmapper/SettingsTable.cxx
parent8e86df886f84fe69f13cfc367a5dd843e6ea917c (diff)
move writerfilter inside sw
writerfilter wants to convert incoming RTF and OOXML files into writer's document model. But it currently has to do so by manipulating the limited subset that we expose through the UNO API. This is both slower and less accurate than having access to the full document model. So move it inside, and then we can strip out various hacks, and optimise imports. Change-Id: Ie1114d28130ef5f9a786531bc552cb8ee7768015 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/165953 Tested-by: Noel Grandin <noel.grandin@collabora.co.uk> Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'sw/qa/writerfilter/cppunittests/dmapper/SettingsTable.cxx')
-rw-r--r--sw/qa/writerfilter/cppunittests/dmapper/SettingsTable.cxx92
1 files changed, 92 insertions, 0 deletions
diff --git a/sw/qa/writerfilter/cppunittests/dmapper/SettingsTable.cxx b/sw/qa/writerfilter/cppunittests/dmapper/SettingsTable.cxx
new file mode 100644
index 000000000000..f8305efb5315
--- /dev/null
+++ b/sw/qa/writerfilter/cppunittests/dmapper/SettingsTable.cxx
@@ -0,0 +1,92 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#include <test/unoapixml_test.hxx>
+
+#include <com/sun/star/beans/XPropertySet.hpp>
+#include <com/sun/star/qa/XDumper.hpp>
+
+#include <test/xmldocptr.hxx>
+
+using namespace com::sun::star;
+
+namespace
+{
+/// Tests for sw/source/writerfilter/dmapper/SettingsTable.cxx.
+class Test : public UnoApiXmlTest
+{
+public:
+ Test()
+ : UnoApiXmlTest("/sw/qa/writerfilter/cppunittests/dmapper/data/")
+ {
+ }
+};
+
+CPPUNIT_TEST_FIXTURE(Test, testDoNotBreakWrappedTables)
+{
+ // Given a document with <w:doNotBreakWrappedTables>:
+ // When importing that document:
+ loadFromFile(u"do-not-break-wrapped-tables.docx");
+
+ // Then make sure that the matching compat flag is set:
+ uno::Reference<lang::XMultiServiceFactory> xDocument(mxComponent, uno::UNO_QUERY);
+ uno::Reference<beans::XPropertySet> xSettings(
+ xDocument->createInstance("com.sun.star.document.Settings"), uno::UNO_QUERY);
+ bool bDoNotBreakWrappedTables{};
+ xSettings->getPropertyValue("DoNotBreakWrappedTables") >>= bDoNotBreakWrappedTables;
+ // Without the accompanying fix in place, this test would have failed, the compat flag was not
+ // set.
+ CPPUNIT_ASSERT(bDoNotBreakWrappedTables);
+}
+
+CPPUNIT_TEST_FIXTURE(Test, testAllowTextAfterFloatingTableBreak)
+{
+ // Given a document with <w:compatSetting w:name="allowTextAfterFloatingTableBreak">:
+ // When importing that document:
+ loadFromFile(u"floattable-wrap-on-all-pages.docx");
+
+ // Then make sure that the matching compat flag is set:
+ uno::Reference<lang::XMultiServiceFactory> xDocument(mxComponent, uno::UNO_QUERY);
+ uno::Reference<beans::XPropertySet> xSettings(
+ xDocument->createInstance("com.sun.star.document.Settings"), uno::UNO_QUERY);
+ bool bAllowTextAfterFloatingTableBreak{};
+ xSettings->getPropertyValue("AllowTextAfterFloatingTableBreak")
+ >>= bAllowTextAfterFloatingTableBreak;
+ // Without the accompanying fix in place, this test would have failed, the compat flag was not
+ // set.
+ CPPUNIT_ASSERT(bAllowTextAfterFloatingTableBreak);
+}
+
+CPPUNIT_TEST_FIXTURE(Test, testAddVerticalFrameOffsetsRTF)
+{
+ // Given a document with a floating table, immediately followed by an inline table:
+ // When importing that document:
+ loadFromFile(u"floattable-vertical-frame-offset.rtf");
+
+ // Then make sure the floating and the inline tables don't overlap:
+ uno::Reference<frame::XModel> xModel(mxComponent, uno::UNO_QUERY);
+ css::uno::Reference<qa::XDumper> xDumper(xModel->getCurrentController(), uno::UNO_QUERY);
+ OString aDump = xDumper->dump("layout").toUtf8();
+ auto pCharBuffer = reinterpret_cast<const xmlChar*>(aDump.getStr());
+ xmlDocUniquePtr pXmlDoc(xmlParseDoc(pCharBuffer));
+ sal_Int32 nFlyBottom = getXPath(pXmlDoc, "//fly/infos/bounds"_ostr, "bottom"_ostr).toInt32();
+ sal_Int32 nTableFrameTop
+ = getXPath(pXmlDoc, "//body/tab/infos/bounds"_ostr, "top"_ostr).toInt32();
+ sal_Int32 nTableTopMargin
+ = getXPath(pXmlDoc, "//body/tab/infos/prtBounds"_ostr, "top"_ostr).toInt32();
+ sal_Int32 nTableTop = nTableFrameTop + nTableTopMargin;
+ // Without the accompanying fix in place, this test would have failed with:
+ // - Expected greater than: 2747
+ // - Actual : 1449
+ // i.e. table top should be ~2748, but was less, leading to an overlap.
+ CPPUNIT_ASSERT_GREATER(nFlyBottom, nTableTop);
+}
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */