build fix
[LibreOffice.git] / starmath / qa / extras / mmlexport-test.cxx
blobb63b22f9b48d7e4d1791f09a4d67aea7179bd3d7
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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/.
8 */
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"
20 #include "smdll.hxx"
21 #include "node.hxx"
22 #include "parse.hxx"
24 #include <memory>
26 namespace {
28 using namespace ::com::sun::star;
30 typedef tools::SvRef<SmDocShell> SmDocShellRef;
32 class MathMLExportTest : public test::BootstrapFixture, public XmlTestTools
34 public:
35 virtual void setUp() override;
36 virtual void tearDown() override;
38 void testBlank();
39 void testTdf97049();
40 void testTdf101022();
42 CPPUNIT_TEST_SUITE(MathMLExportTest);
43 CPPUNIT_TEST(testBlank);
44 CPPUNIT_TEST(testTdf97049);
45 CPPUNIT_TEST(testTdf101022);
46 CPPUNIT_TEST_SUITE_END();
48 protected:
49 virtual void registerNamespaces(xmlXPathContextPtr &pXmlXPathCtx) override;
51 private:
52 xmlDocPtr exportAndParse();
54 SmDocShellRef mxDocShell;
57 void MathMLExportTest::setUp()
59 BootstrapFixture::setUp();
60 SmGlobals::ensure();
61 mxDocShell = new SmDocShell(SfxModelFlags::EMBEDDED_OBJECT |
62 SfxModelFlags::DISABLE_EMBEDDED_SCRIPTS |
63 SfxModelFlags::DISABLE_DOCUMENT_RECOVERY);
66 void MathMLExportTest::tearDown()
68 if (mxDocShell.Is())
69 mxDocShell->DoClose();
70 BootstrapFixture::tearDown();
73 void MathMLExportTest::registerNamespaces(xmlXPathContextPtr &pXmlXPathCtx)
75 xmlXPathRegisterNs(pXmlXPathCtx, BAD_CAST("m"), BAD_CAST("http://www.w3.org/1998/Math/MathML"));
78 xmlDocPtr MathMLExportTest::exportAndParse()
80 utl::TempFile aTempFile;
81 aTempFile.EnableKillingFile();
82 SfxMedium aStoreMedium(aTempFile.GetURL(), StreamMode::STD_WRITE);
83 std::shared_ptr<const SfxFilter> pExportFilter = SfxFilter::GetFilterByName(MATHML_XML);
84 aStoreMedium.SetFilter(pExportFilter);
85 CPPUNIT_ASSERT(mxDocShell->ConvertTo(aStoreMedium));
86 aStoreMedium.Commit();
87 xmlDocPtr pDoc = parseXml(aTempFile);
88 CPPUNIT_ASSERT(pDoc);
89 return pDoc;
92 void MathMLExportTest::testBlank()
94 mxDocShell->SetText("x`y~~z");
95 xmlDocPtr pDoc = exportAndParse();
96 assertXPath(pDoc, "/m:math/m:semantics/m:mrow/m:mspace[1]", "width", "0.5em");
97 assertXPath(pDoc, "/m:math/m:semantics/m:mrow/m:mspace[2]", "width", "4em");
100 void MathMLExportTest::testTdf97049()
102 mxDocShell->SetText("intd {{1 over x} dx}");
103 xmlDocPtr pDoc = exportAndParse();
104 assertXPath(pDoc, "/m:math/m:semantics/m:mrow/m:mo[1]", "stretchy", "true");
105 auto aContent = getXPathContent(pDoc, "/m:math/m:semantics/m:mrow/m:mo[1]");
106 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), aContent.getLength());
107 CPPUNIT_ASSERT_EQUAL(sal_Unicode(0x222B), aContent[0]);
110 void MathMLExportTest::testTdf101022()
112 #define CHECK_MATHVARIANT(capital, small) do \
114 mxDocShell->SetText("%GAMMA %iGAMMA {ital %GAMMA} {nitalic %iGAMMA} " \
115 "%gamma %igamma {ital %gamma} {nitalic %igamma}"); \
116 xmlDocPtr pDoc = exportAndParse(); \
117 if (capital) \
118 assertXPathNoAttribute(pDoc, "/m:math/m:semantics/m:mrow/m:mi[1]", "mathvariant"); \
119 else \
120 assertXPath(pDoc, "/m:math/m:semantics/m:mrow/m:mi[1]", "mathvariant", "normal"); \
121 assertXPathNoAttribute(pDoc, "/m:math/m:semantics/m:mrow/m:mstyle[1]/m:mi[1]", "mathvariant"); \
122 assertXPathNoAttribute(pDoc, "/m:math/m:semantics/m:mrow/m:mi[2]", "mathvariant"); \
123 assertXPath(pDoc, "/m:math/m:semantics/m:mrow/m:mstyle[2]/m:mi[1]", "mathvariant", "normal"); \
124 if (small) \
125 assertXPathNoAttribute(pDoc, "/m:math/m:semantics/m:mrow/m:mi[3]", "mathvariant"); \
126 else \
127 assertXPath(pDoc, "/m:math/m:semantics/m:mrow/m:mi[3]", "mathvariant", "normal"); \
128 assertXPathNoAttribute(pDoc, "/m:math/m:semantics/m:mrow/m:mstyle[3]/m:mi[1]", "mathvariant"); \
129 assertXPathNoAttribute(pDoc, "/m:math/m:semantics/m:mrow/m:mi[4]", "mathvariant"); \
130 assertXPath(pDoc, "/m:math/m:semantics/m:mrow/m:mstyle[4]/m:mi[1]", "mathvariant", "normal"); \
131 mxDocShell->SetText(""); \
133 while (false)
135 CHECK_MATHVARIANT(false, false); // default mode 0
137 mxDocShell->SetGreekCharStyle(1); // mode 1
138 CHECK_MATHVARIANT(true, true);
140 mxDocShell->SetGreekCharStyle(2); // mode 2
141 CHECK_MATHVARIANT(false, true);
143 #undef CHECK_MATHVARIANT
146 CPPUNIT_TEST_SUITE_REGISTRATION(MathMLExportTest);
150 CPPUNIT_PLUGIN_IMPLEMENT();
152 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */