[Libreoffice-commits] core.git: Branch 'libreoffice-6-3' - oox/CppunitTest_oox_mathml.mk oox/Module_oox.mk oox/qa oox/source

Miklos Vajna (via logerrit) logerrit at kemper.freedesktop.org
Fri Nov 15 07:41:41 UTC 2019


 oox/CppunitTest_oox_mathml.mk           |   44 +++++++++++++++++++++
 oox/Module_oox.mk                       |    1 
 oox/qa/unit/data/import-characters.pptx |binary
 oox/qa/unit/mathml.cxx                  |   65 ++++++++++++++++++++++++++++++++
 oox/source/mathml/import.cxx            |   22 +++++-----
 5 files changed, 122 insertions(+), 10 deletions(-)

New commits:
commit 1ae07c3555721cd07a24ace4c20c24f04d73f153
Author:     Miklos Vajna <vmiklos at collabora.com>
AuthorDate: Mon Nov 11 14:08:14 2019 +0100
Commit:     Tamás Zolnai <tamas.zolnai at collabora.com>
CommitDate: Fri Nov 15 08:40:44 2019 +0100

    Related: tdf#117658 PPTX import: ignore math text outside <m:t>
    
    This way a pretty-printed bug document doesn't assert on import with:
    
    soffice.bin: /home/vmiklos/git/libreoffice/master/oox/source/mathml/importutils.cxx:335: void oox::formulaimport::XmlStreamBuilder::appendCharacters(const rtl::OUString&): Assertion `!tags.empty()' failed.
    
    (cherry picked from commit b280c02d584ad403417db0e8840f8ae6de245883)
    
    Change-Id: Icf8b11f3c56076b1ad2dddad196260ee87540020
    Reviewed-on: https://gerrit.libreoffice.org/82665
    Tested-by: Jenkins
    Reviewed-by: Tamás Zolnai <tamas.zolnai at collabora.com>

diff --git a/oox/CppunitTest_oox_mathml.mk b/oox/CppunitTest_oox_mathml.mk
new file mode 100644
index 000000000000..e358a9666fc3
--- /dev/null
+++ b/oox/CppunitTest_oox_mathml.mk
@@ -0,0 +1,44 @@
+# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*-
+#*************************************************************************
+#
+# 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/.
+#
+#*************************************************************************
+
+$(eval $(call gb_CppunitTest_CppunitTest,oox_mathml))
+
+$(eval $(call gb_CppunitTest_use_externals,oox_mathml,\
+	boost_headers \
+))
+
+$(eval $(call gb_CppunitTest_add_exception_objects,oox_mathml, \
+    oox/qa/unit/mathml \
+))
+
+$(eval $(call gb_CppunitTest_use_libraries,oox_mathml, \
+    comphelper \
+    cppu \
+    oox \
+    sal \
+    test \
+    unotest \
+))
+
+$(eval $(call gb_CppunitTest_use_sdk_api,oox_mathml))
+
+$(eval $(call gb_CppunitTest_use_ure,oox_mathml))
+$(eval $(call gb_CppunitTest_use_vcl,oox_mathml))
+
+$(eval $(call gb_CppunitTest_use_rdb,oox_mathml,services))
+
+$(eval $(call gb_CppunitTest_use_custom_headers,oox_mathml,\
+	officecfg/registry \
+))
+
+$(eval $(call gb_CppunitTest_use_configuration,oox_mathml))
+
+# vim: set noet sw=4 ts=4:
diff --git a/oox/Module_oox.mk b/oox/Module_oox.mk
index db79a0f8e093..961e3be66887 100644
--- a/oox/Module_oox.mk
+++ b/oox/Module_oox.mk
@@ -21,6 +21,7 @@ $(eval $(call gb_Module_add_check_targets,oox,\
 	CppunitTest_oox_vba_compression \
 	CppunitTest_oox_vba_encryption \
 	CppunitTest_oox_crypto \
+	CppunitTest_oox_mathml \
 ))
 
 # vim: set noet sw=4 ts=4:
diff --git a/oox/qa/unit/data/import-characters.pptx b/oox/qa/unit/data/import-characters.pptx
new file mode 100644
index 000000000000..29338023641c
Binary files /dev/null and b/oox/qa/unit/data/import-characters.pptx differ
diff --git a/oox/qa/unit/mathml.cxx b/oox/qa/unit/mathml.cxx
new file mode 100644
index 000000000000..632fc566ddb7
--- /dev/null
+++ b/oox/qa/unit/mathml.cxx
@@ -0,0 +1,65 @@
+/* -*- 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/bootstrapfixture.hxx>
+#include <unotest/macros_test.hxx>
+
+#include <com/sun/star/frame/Desktop.hpp>
+#include <com/sun/star/embed/XStorage.hpp>
+
+#include <comphelper/embeddedobjectcontainer.hxx>
+#include <comphelper/processfactory.hxx>
+#include <comphelper/propertyvalue.hxx>
+#include <comphelper/scopeguard.hxx>
+#include <comphelper/storagehelper.hxx>
+
+using namespace ::com::sun::star;
+
+/// oox mathml tests.
+class OoxMathmlTest : public test::BootstrapFixture, public unotest::MacrosTest
+{
+private:
+    uno::Reference<uno::XComponentContext> mxComponentContext;
+    uno::Reference<lang::XComponent> mxComponent;
+
+public:
+    void setUp() override;
+    void tearDown() override;
+    uno::Reference<lang::XComponent>& getComponent() { return mxComponent; }
+};
+
+void OoxMathmlTest::setUp()
+{
+    test::BootstrapFixture::setUp();
+
+    mxComponentContext.set(comphelper::getComponentContext(getMultiServiceFactory()));
+    mxDesktop.set(frame::Desktop::create(mxComponentContext));
+}
+
+void OoxMathmlTest::tearDown()
+{
+    if (mxComponent.is())
+        mxComponent->dispose();
+
+    test::BootstrapFixture::tearDown();
+}
+
+char const DATA_DIRECTORY[] = "/oox/qa/unit/data/";
+
+CPPUNIT_TEST_FIXTURE(OoxMathmlTest, testImportCharacters)
+{
+    OUString aURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + "import-characters.pptx";
+    // Without the accompanying fix in place, this failed with an assertion failure on import.
+    getComponent() = loadFromDesktop(aURL);
+    CPPUNIT_ASSERT(getComponent().is());
+}
+
+CPPUNIT_PLUGIN_IMPLEMENT();
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/oox/source/mathml/import.cxx b/oox/source/mathml/import.cxx
index 5a02f8906955..ec338c451638 100644
--- a/oox/source/mathml/import.cxx
+++ b/oox/source/mathml/import.cxx
@@ -32,7 +32,7 @@ class LazyMathBufferingContext : public core::ContextHandler
 {
 private:
     XmlStreamBuilder & m_rBuilder;
-    long m_Counter;
+    std::vector<sal_Int32> m_OpenElements;
 
 public:
     LazyMathBufferingContext(core::ContextHandler const& rParent,
@@ -51,7 +51,6 @@ LazyMathBufferingContext::LazyMathBufferingContext(
         core::ContextHandler const& rParent, drawingml::TextParagraph & rPara)
     : core::ContextHandler(rParent)
     , m_rBuilder(rPara.GetMathXml())
-    , m_Counter(0)
 {
 }
 
@@ -59,22 +58,22 @@ void SAL_CALL LazyMathBufferingContext::startFastElement(
         sal_Int32 const nElement,
         uno::Reference<xml::sax::XFastAttributeList> const& xAttrs)
 {
-    if (0 < m_Counter) // ignore a14:m
+    if (0 < m_OpenElements.size()) // ignore a14:m
     {   // ignore outer oMathPara
-        if (1 != m_Counter || OOX_TOKEN(officeMath, oMathPara) != nElement)
+        if (1 != m_OpenElements.size() || OOX_TOKEN(officeMath, oMathPara) != nElement)
         {
             m_rBuilder.appendOpeningTag(nElement, xAttrs);
         }
     }
-    ++m_Counter;
+    m_OpenElements.push_back(nElement);
 }
 
 void SAL_CALL LazyMathBufferingContext::endFastElement(sal_Int32 const nElement)
 {
-    --m_Counter;
-    if (0 < m_Counter) // ignore a14:m
+    m_OpenElements.pop_back();
+    if (0 < m_OpenElements.size()) // ignore a14:m
     {   // ignore outer oMathPara
-        if (1 != m_Counter || OOX_TOKEN(officeMath, oMathPara) != nElement)
+        if (1 != m_OpenElements.size() || OOX_TOKEN(officeMath, oMathPara) != nElement)
         {
             m_rBuilder.appendClosingTag(nElement);
         }
@@ -90,9 +89,12 @@ LazyMathBufferingContext::createFastChildContext(sal_Int32 const,
 
 void SAL_CALL LazyMathBufferingContext::characters(OUString const& rChars)
 {
-    if (0 < m_Counter) // ignore a14:m
+    if (0 < m_OpenElements.size()) // ignore a14:m
     {
-        m_rBuilder.appendCharacters(rChars);
+        if (m_OpenElements.back() == OOX_TOKEN(officeMath, t))
+        {
+            m_rBuilder.appendCharacters(rChars);
+        }
     }
 }
 


More information about the Libreoffice-commits mailing list