summaryrefslogtreecommitdiffstats
path: root/starmath/qa/extras
diff options
context:
space:
mode:
Diffstat (limited to 'starmath/qa/extras')
-rw-r--r--starmath/qa/extras/data/color.mml24
-rw-r--r--starmath/qa/extras/data/maction.mml10
-rw-r--r--starmath/qa/extras/data/mspace.mml12
-rw-r--r--starmath/qa/extras/data/mthmlentities.mml9
-rw-r--r--starmath/qa/extras/data/ns-prefix-math.mml13
-rw-r--r--starmath/qa/extras/data/simple.mml13
-rw-r--r--starmath/qa/extras/data/tdf103430.mml17
-rw-r--r--starmath/qa/extras/data/tdf103500.mml41
-rw-r--r--starmath/qa/extras/data/tdf137008.mml1
-rw-r--r--starmath/qa/extras/data/tdf99556-1.mml3
-rw-r--r--starmath/qa/extras/mmlexport-test.cxx155
-rw-r--r--starmath/qa/extras/mmlimport-test.cxx191
12 files changed, 489 insertions, 0 deletions
diff --git a/starmath/qa/extras/data/color.mml b/starmath/qa/extras/data/color.mml
new file mode 100644
index 000000000..41294eff8
--- /dev/null
+++ b/starmath/qa/extras/data/color.mml
@@ -0,0 +1,24 @@
+<math xmlns="http://www.w3.org/1998/Math/MathML">
+ <mrow>
+ <mi mathcolor="black">b</mi>
+ <mi mathcolor="white">w</mi>
+ <mi mathcolor="red">r</mi>
+ <mi mathcolor="green">g</mi>
+ <mi mathcolor="blue">b</mi>
+ <mi mathcolor="yellow">y</mi>
+ <mi mathcolor="silver">s</mi>
+ <mi mathcolor="gray">g</mi>
+ <mi mathcolor="maroon">m</mi>
+ <mi mathcolor="purple">p</mi>
+ <mi mathcolor="lime">l</mi>
+ <mi mathcolor="olive">o</mi>
+ <mi mathcolor="navy">n</mi>
+ <mi mathcolor="teal">t</mi>
+ <mi mathcolor="aqua">a</mi>
+ <mi mathcolor="fuchsia">f</mi>
+ <mi mathcolor="#DC143C">c</mi>
+ <mi mathcolor="#FFB781">a</mi>
+ <mi mathcolor="#FF0">y</mi>
+ <mi mathcolor="#DC143D">x</mi>
+ </mrow>
+</math>
diff --git a/starmath/qa/extras/data/maction.mml b/starmath/qa/extras/data/maction.mml
new file mode 100644
index 000000000..365008799
--- /dev/null
+++ b/starmath/qa/extras/data/maction.mml
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<math xmlns="http://www.w3.org/1998/Math/MathML">
+ <mrow>
+ <mtable>
+ <mtr><maction actiontype="toggle"><mn>1</mn><mn>0</mn><mn>0</mn></maction></mtr>
+ <mtr><maction actiontype="toggle" selection="2"><mn>0</mn><mn>2</mn><mn>0</mn></maction></mtr>
+ <mtr><maction actiontype="toggle" selection="3"><mn>0</mn><mn>0</mn><mn>3</mn></maction></mtr>
+ </mtable>
+ </mrow>
+</math>
diff --git a/starmath/qa/extras/data/mspace.mml b/starmath/qa/extras/data/mspace.mml
new file mode 100644
index 000000000..190651094
--- /dev/null
+++ b/starmath/qa/extras/data/mspace.mml
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<math xmlns="http://www.w3.org/1998/Math/MathML">
+ <mrow>
+ <mi>a</mi>
+ <mspace />
+ <mi>b</mi>
+ <mspace width="2em" />
+ <mi>c</mi>
+ <mspace width="5.5em" />
+ <mi>d</mi>
+ </mrow>
+</math>
diff --git a/starmath/qa/extras/data/mthmlentities.mml b/starmath/qa/extras/data/mthmlentities.mml
new file mode 100644
index 000000000..328d689ce
--- /dev/null
+++ b/starmath/qa/extras/data/mthmlentities.mml
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<math xmlns="http://www.w3.org/1998/Math/MathML" display="block">
+ <semantics>
+ <mi>&#x3C3;</mi>
+ <mi>&#x221E;</mi>
+ <mi>&infin;</mi>
+ <mi>&sigma;</mi>
+ </semantics>
+</math>
diff --git a/starmath/qa/extras/data/ns-prefix-math.mml b/starmath/qa/extras/data/ns-prefix-math.mml
new file mode 100644
index 000000000..c4c961223
--- /dev/null
+++ b/starmath/qa/extras/data/ns-prefix-math.mml
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<math:math xmlns:math="http://www.w3.org/1998/Math/MathML">
+ <math:msup>
+ <math:mfenced>
+ <math:mrow>
+ <math:mi>a</math:mi>
+ <math:mo>+</math:mo>
+ <math:mi>b</math:mi>
+ </math:mrow>
+ </math:mfenced>
+ <math:mn>2</math:mn>
+ </math:msup>
+</math:math>
diff --git a/starmath/qa/extras/data/simple.mml b/starmath/qa/extras/data/simple.mml
new file mode 100644
index 000000000..822d1a709
--- /dev/null
+++ b/starmath/qa/extras/data/simple.mml
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<math xmlns="http://www.w3.org/1998/Math/MathML">
+ <msup>
+ <mfenced>
+ <mrow>
+ <mi>a</mi>
+ <mo>+</mo>
+ <mi>b</mi>
+ </mrow>
+ </mfenced>
+ <mn>2</mn>
+ </msup>
+</math>
diff --git a/starmath/qa/extras/data/tdf103430.mml b/starmath/qa/extras/data/tdf103430.mml
new file mode 100644
index 000000000..f8ea8f8d2
--- /dev/null
+++ b/starmath/qa/extras/data/tdf103430.mml
@@ -0,0 +1,17 @@
+<math xmlns="http://www.w3.org/1998/Math/MathML">
+ <mfrac>
+ <mrow>
+ <msup>
+ <mo form="prefix" rspace="0">d</mo>
+ <mn>2</mn>
+ </msup>
+ <mi mathvariant="normal" mathcolor="blue">y</mi>
+ </mrow>
+ <mrow>
+ <mstyle mathcolor="#ffb781">
+ <mo fontstyle="italic" fontweight="bold" mathvariant="normal" form="prefix" rspace="0">d</mo>
+ </mstyle>
+ <mi fontfamily="serif" mathvariant="sans-serif-bold-italic" mathcolor="red">x</mi>
+ </mrow>
+ </mfrac>
+</math>
diff --git a/starmath/qa/extras/data/tdf103500.mml b/starmath/qa/extras/data/tdf103500.mml
new file mode 100644
index 000000000..7c4966985
--- /dev/null
+++ b/starmath/qa/extras/data/tdf103500.mml
@@ -0,0 +1,41 @@
+<math xmlns="http://www.w3.org/1998/Math/MathML">
+ <mrow>
+ <mrow>
+ <munderover>
+ <mo stretchy="false">∫</mo>
+ <mi>a</mi>
+ <mi>b</mi>
+ </munderover>
+ <mrow>
+ <mfrac>
+ <mn>1</mn>
+ <mi>x</mi>
+ </mfrac>
+ <mspace width="0.5em"/>
+ <mstyle mathvariant="normal">
+ <mi mathvariant="normal">d</mi>
+ </mstyle>
+ <mi>x</mi>
+ </mrow>
+ </mrow>
+ <mo stretchy="false">=</mo>
+ <mrow>
+ <munderover>
+ <mo stretchy="true">∫</mo>
+ <mi>a</mi>
+ <mi>b</mi>
+ </munderover>
+ <mrow>
+ <mfrac>
+ <mn>1</mn>
+ <mi>y</mi>
+ </mfrac>
+ <mspace width="0.5em"/>
+ <mstyle mathvariant="normal">
+ <mi mathvariant="normal">d</mi>
+ </mstyle>
+ <mi>y</mi>
+ </mrow>
+ </mrow>
+ </mrow>
+</math>
diff --git a/starmath/qa/extras/data/tdf137008.mml b/starmath/qa/extras/data/tdf137008.mml
new file mode 100644
index 000000000..bc6ee25db
--- /dev/null
+++ b/starmath/qa/extras/data/tdf137008.mml
@@ -0,0 +1 @@
+<math xmlns='http://www.w3.org/1998/Math/MathML'><mtable><mtr><mtd></mtd></mtr><mtr></mtr></mtable></math> \ No newline at end of file
diff --git a/starmath/qa/extras/data/tdf99556-1.mml b/starmath/qa/extras/data/tdf99556-1.mml
new file mode 100644
index 000000000..0eae8b2df
--- /dev/null
+++ b/starmath/qa/extras/data/tdf99556-1.mml
@@ -0,0 +1,3 @@
+<math xmlns="http://www.w3.org/1998/Math/MathML">
+<msqrt/>
+</math>
diff --git a/starmath/qa/extras/mmlexport-test.cxx b/starmath/qa/extras/mmlexport-test.cxx
new file mode 100644
index 000000000..d41ba41e6
--- /dev/null
+++ b/starmath/qa/extras/mmlexport-test.cxx
@@ -0,0 +1,155 @@
+/* -*- 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 <sal/config.h>
+
+#include <o3tl/cppunittraitshelper.hxx>
+#include <test/bootstrapfixture.hxx>
+#include <test/xmltesttools.hxx>
+#include <unotools/tempfile.hxx>
+
+#include <sfx2/docfile.hxx>
+#include <sfx2/docfilt.hxx>
+#include <sfx2/sfxmodelfactory.hxx>
+
+#include <document.hxx>
+#include <smdll.hxx>
+
+#include <memory>
+
+namespace
+{
+using namespace ::com::sun::star;
+
+typedef tools::SvRef<SmDocShell> SmDocShellRef;
+
+class MathMLExportTest : public test::BootstrapFixture, public XmlTestTools
+{
+public:
+ virtual void setUp() override;
+ virtual void tearDown() override;
+
+ void testBlank();
+ void testTdf97049();
+ void testTdf101022();
+
+ CPPUNIT_TEST_SUITE(MathMLExportTest);
+ CPPUNIT_TEST(testBlank);
+ CPPUNIT_TEST(testTdf97049);
+ CPPUNIT_TEST(testTdf101022);
+ CPPUNIT_TEST_SUITE_END();
+
+protected:
+ virtual void registerNamespaces(xmlXPathContextPtr& pXmlXPathCtx) override;
+
+private:
+ xmlDocUniquePtr exportAndParse();
+
+ SmDocShellRef mxDocShell;
+};
+
+void MathMLExportTest::setUp()
+{
+ BootstrapFixture::setUp();
+ SmGlobals::ensure();
+ mxDocShell
+ = new SmDocShell(SfxModelFlags::EMBEDDED_OBJECT | SfxModelFlags::DISABLE_EMBEDDED_SCRIPTS
+ | SfxModelFlags::DISABLE_DOCUMENT_RECOVERY);
+}
+
+void MathMLExportTest::tearDown()
+{
+ if (mxDocShell.is())
+ mxDocShell->DoClose();
+ BootstrapFixture::tearDown();
+}
+
+void MathMLExportTest::registerNamespaces(xmlXPathContextPtr& pXmlXPathCtx)
+{
+ xmlXPathRegisterNs(pXmlXPathCtx, BAD_CAST("m"), BAD_CAST("http://www.w3.org/1998/Math/MathML"));
+}
+
+xmlDocUniquePtr MathMLExportTest::exportAndParse()
+{
+ utl::TempFile aTempFile;
+ aTempFile.EnableKillingFile();
+ SfxMedium aStoreMedium(aTempFile.GetURL(), StreamMode::STD_WRITE);
+ std::shared_ptr<const SfxFilter> pExportFilter = SfxFilter::GetFilterByName(MATHML_XML);
+ aStoreMedium.SetFilter(pExportFilter);
+ CPPUNIT_ASSERT(mxDocShell->ConvertTo(aStoreMedium));
+ aStoreMedium.Commit();
+ xmlDocUniquePtr pDoc = parseXml(aTempFile);
+ CPPUNIT_ASSERT(pDoc);
+ return pDoc;
+}
+
+void MathMLExportTest::testBlank()
+{
+ mxDocShell->SetText("x`y~~z");
+ xmlDocUniquePtr pDoc = exportAndParse();
+ assertXPath(pDoc, "/m:math/m:semantics/m:mrow/m:mspace[1]", "width", "0.5em");
+ assertXPath(pDoc, "/m:math/m:semantics/m:mrow/m:mspace[2]", "width", "4em");
+}
+
+void MathMLExportTest::testTdf97049()
+{
+ mxDocShell->SetText("intd {{1 over x} dx}");
+ xmlDocUniquePtr pDoc = exportAndParse();
+ assertXPath(pDoc, "/m:math/m:semantics/m:mrow/m:mo[1]", "stretchy", "true");
+ auto aContent = getXPathContent(pDoc, "/m:math/m:semantics/m:mrow/m:mo[1]");
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(1), aContent.getLength());
+ CPPUNIT_ASSERT_EQUAL(u'\x222B', aContent[0]);
+}
+
+void MathMLExportTest::testTdf101022()
+{
+#define CHECK_MATHVARIANT(capital, small) \
+ do \
+ { \
+ mxDocShell->SetText("%GAMMA %iGAMMA {ital %GAMMA} {nitalic %iGAMMA} " \
+ "%gamma %igamma {ital %gamma} {nitalic %igamma}"); \
+ xmlDocUniquePtr pDoc = exportAndParse(); \
+ if (capital) \
+ assertXPathNoAttribute(pDoc, "/m:math/m:semantics/m:mrow/m:mi[1]", "mathvariant"); \
+ else \
+ assertXPath(pDoc, "/m:math/m:semantics/m:mrow/m:mi[1]", "mathvariant", "normal"); \
+ assertXPathNoAttribute(pDoc, "/m:math/m:semantics/m:mrow/m:mstyle[1]/m:mi[1]", \
+ "mathvariant"); \
+ assertXPathNoAttribute(pDoc, "/m:math/m:semantics/m:mrow/m:mi[2]", "mathvariant"); \
+ assertXPath(pDoc, "/m:math/m:semantics/m:mrow/m:mstyle[2]/m:mi[1]", "mathvariant", \
+ "normal"); \
+ if (small) \
+ assertXPathNoAttribute(pDoc, "/m:math/m:semantics/m:mrow/m:mi[3]", "mathvariant"); \
+ else \
+ assertXPath(pDoc, "/m:math/m:semantics/m:mrow/m:mi[3]", "mathvariant", "normal"); \
+ assertXPathNoAttribute(pDoc, "/m:math/m:semantics/m:mrow/m:mstyle[3]/m:mi[1]", \
+ "mathvariant"); \
+ assertXPathNoAttribute(pDoc, "/m:math/m:semantics/m:mrow/m:mi[4]", "mathvariant"); \
+ assertXPath(pDoc, "/m:math/m:semantics/m:mrow/m:mstyle[4]/m:mi[1]", "mathvariant", \
+ "normal"); \
+ mxDocShell->SetText(""); \
+ } while (false)
+
+ CHECK_MATHVARIANT(false, true); // default mode 2
+
+ mxDocShell->SetGreekCharStyle(1); // mode 1
+ CHECK_MATHVARIANT(true, true);
+
+ mxDocShell->SetGreekCharStyle(0); // mode 0
+ CHECK_MATHVARIANT(false, false);
+
+#undef CHECK_MATHVARIANT
+}
+
+CPPUNIT_TEST_SUITE_REGISTRATION(MathMLExportTest);
+}
+
+CPPUNIT_PLUGIN_IMPLEMENT();
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/starmath/qa/extras/mmlimport-test.cxx b/starmath/qa/extras/mmlimport-test.cxx
new file mode 100644
index 000000000..323b0e0fb
--- /dev/null
+++ b/starmath/qa/extras/mmlimport-test.cxx
@@ -0,0 +1,191 @@
+/* -*- 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 <sal/config.h>
+#include <test/bootstrapfixture.hxx>
+
+#include <comphelper/fileformat.h>
+
+#include <sfx2/docfile.hxx>
+#include <sfx2/docfilt.hxx>
+#include <sfx2/sfxmodelfactory.hxx>
+
+#include <document.hxx>
+#include <smdll.hxx>
+
+namespace
+{
+using namespace ::com::sun::star;
+
+typedef tools::SvRef<SmDocShell> SmDocShellRef;
+
+class Test : public test::BootstrapFixture
+{
+public:
+ virtual void setUp() override;
+ virtual void tearDown() override;
+
+ void testColor();
+ void testSimple();
+ void testNsPrefixMath();
+ void testMaction();
+ void testMspace();
+ void testtdf99556();
+ void testTdf103430();
+ void testTdf103500();
+ void testTdf137008();
+ void testMathmlEntities();
+
+ CPPUNIT_TEST_SUITE(Test);
+ CPPUNIT_TEST(testColor);
+ CPPUNIT_TEST(testSimple);
+ CPPUNIT_TEST(testNsPrefixMath);
+ CPPUNIT_TEST(testMaction);
+ CPPUNIT_TEST(testMspace);
+ CPPUNIT_TEST(testtdf99556);
+ CPPUNIT_TEST(testTdf103430);
+ CPPUNIT_TEST(testTdf103500);
+ CPPUNIT_TEST(testTdf137008);
+ CPPUNIT_TEST(testMathmlEntities);
+ CPPUNIT_TEST_SUITE_END();
+
+private:
+ void loadURL(const OUString& rURL)
+ {
+ // Cf.
+ // filter/source/config/fragments/filters/MathML_XML__Math_.xcu
+ auto pFilter = std::make_shared<SfxFilter>(
+ MATHML_XML, OUString(),
+ SfxFilterFlags::IMPORT | SfxFilterFlags::EXPORT | SfxFilterFlags::TEMPLATE,
+ SotClipboardFormatId::STARCALC_8, "MathML 2.0", OUString(), OUString(),
+ "private:factory/smath*");
+ pFilter->SetVersion(SOFFICE_FILEFORMAT_60);
+
+ mxDocShell = new SmDocShell(SfxModelFlags::EMBEDDED_OBJECT
+ | SfxModelFlags::DISABLE_EMBEDDED_SCRIPTS
+ | SfxModelFlags::DISABLE_DOCUMENT_RECOVERY);
+
+ SfxMedium* pSrcMed = new SfxMedium(rURL, StreamMode::STD_READ);
+ pSrcMed->SetFilter(pFilter);
+ pSrcMed->UseInteractionHandler(false);
+ bool bLoaded = mxDocShell->DoLoad(pSrcMed);
+ CPPUNIT_ASSERT_MESSAGE(
+ OString("failed to load " + OUStringToOString(rURL, RTL_TEXTENCODING_UTF8)).getStr(),
+ bLoaded);
+ }
+
+ SmDocShellRef mxDocShell;
+};
+
+void Test::setUp()
+{
+ BootstrapFixture::setUp();
+ SmGlobals::ensure();
+}
+
+void Test::tearDown()
+{
+ if (mxDocShell.is())
+ mxDocShell->DoClose();
+ BootstrapFixture::tearDown();
+}
+
+void Test::testColor()
+{
+ loadURL(m_directories.getURLFromSrc(u"starmath/qa/extras/data/color.mml"));
+ CPPUNIT_ASSERT_EQUAL(OUString("{ color black b"
+ " color white w"
+ " color red r"
+ " color green g"
+ " color blue b"
+ " color yellow y"
+ " color silver s"
+ " color gray g"
+ " color maroon m"
+ " color purple p"
+ " color lime l"
+ " color olive o"
+ " color navy n"
+ " color teal t"
+ " color aqua a"
+ " color fuchsia f"
+ " color crimson c"
+ " color dvip apricot"
+ " a color yellow y"
+ " color rgb 220 20 61 x }"),
+ mxDocShell->GetText());
+}
+
+void Test::testSimple()
+{
+ loadURL(m_directories.getURLFromSrc(u"starmath/qa/extras/data/simple.mml"));
+ CPPUNIT_ASSERT_EQUAL_MESSAGE("loaded text", OUString("left ( { a + b } right ) ^ 2"),
+ mxDocShell->GetText());
+}
+
+void Test::testNsPrefixMath()
+{
+ loadURL(m_directories.getURLFromSrc(u"starmath/qa/extras/data/ns-prefix-math.mml"));
+ CPPUNIT_ASSERT_EQUAL_MESSAGE("loaded text", OUString("left ( { a + b } right ) ^ 2"),
+ mxDocShell->GetText());
+}
+
+void Test::testMaction()
+{
+ loadURL(m_directories.getURLFromSrc(u"starmath/qa/extras/data/maction.mml"));
+ CPPUNIT_ASSERT_EQUAL_MESSAGE("loaded text", OUString("matrix{ 1 ## 2 ## 3 }"),
+ mxDocShell->GetText());
+}
+
+void Test::testMspace()
+{
+ loadURL(m_directories.getURLFromSrc(u"starmath/qa/extras/data/mspace.mml"));
+ CPPUNIT_ASSERT_EQUAL(OUString("{ a b ~ c ~~``` d }"), mxDocShell->GetText());
+}
+
+void Test::testtdf99556()
+{
+ loadURL(m_directories.getURLFromSrc(u"starmath/qa/extras/data/tdf99556-1.mml"));
+ CPPUNIT_ASSERT_EQUAL_MESSAGE("loaded text", OUString("sqrt { }"), mxDocShell->GetText());
+}
+
+void Test::testTdf103430()
+{
+ loadURL(m_directories.getURLFromSrc(u"starmath/qa/extras/data/tdf103430.mml"));
+ CPPUNIT_ASSERT_EQUAL(OUString("frac { { nitalic d ^ 2 nitalic color blue y } } { { color dvip "
+ "apricot nitalic d font sans bold italic color red x } }"),
+ mxDocShell->GetText());
+}
+
+void Test::testTdf103500()
+{
+ loadURL(m_directories.getURLFromSrc(u"starmath/qa/extras/data/tdf103500.mml"));
+ CPPUNIT_ASSERT_EQUAL(OUString("{ { int csup b csub a { frac { 1 } { x } ` nitalic d x } } = { "
+ "intd csup b csub a { frac { 1 } { y } ` nitalic d y } } }"),
+ mxDocShell->GetText());
+}
+
+void Test::testTdf137008()
+{
+ // Without the fix in place, this test would have crashed
+ loadURL(m_directories.getURLFromSrc(u"starmath/qa/extras/data/tdf137008.mml"));
+ CPPUNIT_ASSERT_EQUAL(OUString("matrix{ { } # ## # }"), mxDocShell->GetText());
+}
+void Test::testMathmlEntities()
+{
+ loadURL(m_directories.getURLFromSrc(u"starmath/qa/extras/data/mthmlentities.mml"));
+ CPPUNIT_ASSERT_EQUAL(OUString(u"{ \u03C3 \u221E \u221E \u03C3 }"), mxDocShell->GetText());
+}
+
+CPPUNIT_TEST_SUITE_REGISTRATION(Test);
+}
+
+CPPUNIT_PLUGIN_IMPLEMENT();
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */