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 <sal/config.h>
11 #include <test/bootstrapfixture.hxx>
12 #include <test/xmltesttools.hxx>
13 #include <unotools/tempfile.hxx>
15 #include <sfx2/docfile.hxx>
16 #include <sfx2/docfilt.hxx>
17 #include <sfx2/sfxmodelfactory.hxx>
19 #include <document.hxx>
26 using namespace ::com::sun::star
;
28 typedef tools::SvRef
<SmDocShell
> SmDocShellRef
;
30 class MathMLExportTest
: public test::BootstrapFixture
, public XmlTestTools
33 virtual void setUp() override
;
34 virtual void tearDown() override
;
40 CPPUNIT_TEST_SUITE(MathMLExportTest
);
41 CPPUNIT_TEST(testBlank
);
42 CPPUNIT_TEST(testTdf97049
);
43 CPPUNIT_TEST(testTdf101022
);
44 CPPUNIT_TEST_SUITE_END();
47 virtual void registerNamespaces(xmlXPathContextPtr
&pXmlXPathCtx
) override
;
50 xmlDocPtr
exportAndParse();
52 SmDocShellRef mxDocShell
;
55 void MathMLExportTest::setUp()
57 BootstrapFixture::setUp();
59 mxDocShell
= new SmDocShell(SfxModelFlags::EMBEDDED_OBJECT
|
60 SfxModelFlags::DISABLE_EMBEDDED_SCRIPTS
|
61 SfxModelFlags::DISABLE_DOCUMENT_RECOVERY
);
64 void MathMLExportTest::tearDown()
67 mxDocShell
->DoClose();
68 BootstrapFixture::tearDown();
71 void MathMLExportTest::registerNamespaces(xmlXPathContextPtr
&pXmlXPathCtx
)
73 xmlXPathRegisterNs(pXmlXPathCtx
, BAD_CAST("m"), BAD_CAST("http://www.w3.org/1998/Math/MathML"));
76 xmlDocPtr
MathMLExportTest::exportAndParse()
78 utl::TempFile aTempFile
;
79 aTempFile
.EnableKillingFile();
80 SfxMedium
aStoreMedium(aTempFile
.GetURL(), StreamMode::STD_WRITE
);
81 std::shared_ptr
<const SfxFilter
> pExportFilter
= SfxFilter::GetFilterByName(MATHML_XML
);
82 aStoreMedium
.SetFilter(pExportFilter
);
83 CPPUNIT_ASSERT(mxDocShell
->ConvertTo(aStoreMedium
));
84 aStoreMedium
.Commit();
85 xmlDocPtr pDoc
= parseXml(aTempFile
);
90 void MathMLExportTest::testBlank()
92 mxDocShell
->SetText("x`y~~z");
93 xmlDocPtr pDoc
= exportAndParse();
94 assertXPath(pDoc
, "/m:math/m:semantics/m:mrow/m:mspace[1]", "width", "0.5em");
95 assertXPath(pDoc
, "/m:math/m:semantics/m:mrow/m:mspace[2]", "width", "4em");
98 void MathMLExportTest::testTdf97049()
100 mxDocShell
->SetText("intd {{1 over x} dx}");
101 xmlDocPtr pDoc
= exportAndParse();
102 assertXPath(pDoc
, "/m:math/m:semantics/m:mrow/m:mo[1]", "stretchy", "true");
103 auto aContent
= getXPathContent(pDoc
, "/m:math/m:semantics/m:mrow/m:mo[1]");
104 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), aContent
.getLength());
105 CPPUNIT_ASSERT_EQUAL(u
'\x222B', aContent
[0]);
108 void MathMLExportTest::testTdf101022()
110 #define CHECK_MATHVARIANT(capital, small) do \
112 mxDocShell->SetText("%GAMMA %iGAMMA {ital %GAMMA} {nitalic %iGAMMA} " \
113 "%gamma %igamma {ital %gamma} {nitalic %igamma}"); \
114 xmlDocPtr pDoc = exportAndParse(); \
116 assertXPathNoAttribute(pDoc, "/m:math/m:semantics/m:mrow/m:mi[1]", "mathvariant"); \
118 assertXPath(pDoc, "/m:math/m:semantics/m:mrow/m:mi[1]", "mathvariant", "normal"); \
119 assertXPathNoAttribute(pDoc, "/m:math/m:semantics/m:mrow/m:mstyle[1]/m:mi[1]", "mathvariant"); \
120 assertXPathNoAttribute(pDoc, "/m:math/m:semantics/m:mrow/m:mi[2]", "mathvariant"); \
121 assertXPath(pDoc, "/m:math/m:semantics/m:mrow/m:mstyle[2]/m:mi[1]", "mathvariant", "normal"); \
123 assertXPathNoAttribute(pDoc, "/m:math/m:semantics/m:mrow/m:mi[3]", "mathvariant"); \
125 assertXPath(pDoc, "/m:math/m:semantics/m:mrow/m:mi[3]", "mathvariant", "normal"); \
126 assertXPathNoAttribute(pDoc, "/m:math/m:semantics/m:mrow/m:mstyle[3]/m:mi[1]", "mathvariant"); \
127 assertXPathNoAttribute(pDoc, "/m:math/m:semantics/m:mrow/m:mi[4]", "mathvariant"); \
128 assertXPath(pDoc, "/m:math/m:semantics/m:mrow/m:mstyle[4]/m:mi[1]", "mathvariant", "normal"); \
129 mxDocShell->SetText(""); \
133 CHECK_MATHVARIANT(false, true); // default mode 2
135 mxDocShell
->SetGreekCharStyle(1); // mode 1
136 CHECK_MATHVARIANT(true, true);
138 mxDocShell
->SetGreekCharStyle(0); // mode 0
139 CHECK_MATHVARIANT(false, false);
141 #undef CHECK_MATHVARIANT
144 CPPUNIT_TEST_SUITE_REGISTRATION(MathMLExportTest
);
148 CPPUNIT_PLUGIN_IMPLEMENT();
150 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */