Revert "tdf#158280 Replace usage of InputDialog with SvxNameDialog"
[LibreOffice.git] / starmath / qa / extras / mmlexport-test.cxx
blobc0b34afa3f761191829fe51f5febfb445c38f704
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/unoapixml_test.hxx>
13 #include <o3tl/cppunittraitshelper.hxx>
14 #include <sfx2/sfxbasemodel.hxx>
16 #include <document.hxx>
17 #include <smdll.hxx>
19 #include <memory>
21 using namespace ::com::sun::star;
23 class MathMLExportTest : public UnoApiXmlTest
25 public:
26 MathMLExportTest()
27 : UnoApiXmlTest(u"starmath/qa/extras/data/"_ustr)
31 void testBlank();
32 void testTdf97049();
33 void testTdf101022();
34 void testMaj();
35 void testHadd();
37 CPPUNIT_TEST_SUITE(MathMLExportTest);
38 CPPUNIT_TEST(testBlank);
39 CPPUNIT_TEST(testTdf97049);
40 CPPUNIT_TEST(testTdf101022);
41 CPPUNIT_TEST(testMaj);
42 CPPUNIT_TEST(testHadd);
43 CPPUNIT_TEST_SUITE_END();
45 protected:
46 virtual void registerNamespaces(xmlXPathContextPtr& pXmlXPathCtx) override;
48 void checkMathVariant(SmDocShell& rDocShell, bool bCapital, bool bSmall);
51 void MathMLExportTest::registerNamespaces(xmlXPathContextPtr& pXmlXPathCtx)
53 xmlXPathRegisterNs(pXmlXPathCtx, BAD_CAST("m"), BAD_CAST("http://www.w3.org/1998/Math/MathML"));
56 void MathMLExportTest::testBlank()
58 loadFromURL(u"private:factory/smath"_ustr);
59 SfxBaseModel* pModel = dynamic_cast<SfxBaseModel*>(mxComponent.get());
60 SmDocShell* pDocShell = static_cast<SmDocShell*>(pModel->GetObjectShell());
61 pDocShell->SetText(u"x`y~~z"_ustr);
62 save(u"MathML XML (Math)"_ustr);
63 xmlDocUniquePtr pDoc = parseXml(maTempFile);
64 CPPUNIT_ASSERT(pDoc);
65 assertXPath(pDoc, "/m:math/m:semantics/m:mrow/m:mspace[1]", "width", u"0.5em");
66 assertXPath(pDoc, "/m:math/m:semantics/m:mrow/m:mspace[2]", "width", u"4em");
69 void MathMLExportTest::testTdf97049()
71 loadFromURL(u"private:factory/smath"_ustr);
72 SfxBaseModel* pModel = dynamic_cast<SfxBaseModel*>(mxComponent.get());
73 SmDocShell* pDocShell = static_cast<SmDocShell*>(pModel->GetObjectShell());
74 pDocShell->SetText(u"intd {{1 over x} dx}"_ustr);
75 save(u"MathML XML (Math)"_ustr);
76 xmlDocUniquePtr pDoc = parseXml(maTempFile);
77 CPPUNIT_ASSERT(pDoc);
78 assertXPath(pDoc, "/m:math/m:semantics/m:mrow/m:mo[1]", "stretchy", u"true");
79 auto aContent = getXPathContent(pDoc, "/m:math/m:semantics/m:mrow/m:mo[1]");
80 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), aContent.getLength());
81 CPPUNIT_ASSERT_EQUAL(u'\x222B', aContent[0]);
84 void MathMLExportTest::checkMathVariant(SmDocShell& rDocShell, bool bCapital, bool bSmall)
86 rDocShell.SetText(u"%GAMMA %iGAMMA {ital %GAMMA} {nitalic %iGAMMA} "
87 "%gamma %igamma {ital %gamma} {nitalic %igamma}"_ustr);
88 save(u"MathML XML (Math)"_ustr);
89 xmlDocUniquePtr pDoc = parseXml(maTempFile);
90 CPPUNIT_ASSERT(pDoc);
91 if (bCapital)
92 assertXPathNoAttribute(pDoc, "/m:math/m:semantics/m:mrow/m:mi[1]", "mathvariant");
93 else
94 assertXPath(pDoc, "/m:math/m:semantics/m:mrow/m:mi[1]", "mathvariant", u"normal");
95 assertXPathNoAttribute(pDoc, "/m:math/m:semantics/m:mrow/m:mstyle[1]/m:mi[1]", "mathvariant");
96 assertXPathNoAttribute(pDoc, "/m:math/m:semantics/m:mrow/m:mi[2]", "mathvariant");
97 assertXPath(pDoc, "/m:math/m:semantics/m:mrow/m:mstyle[2]/m:mi[1]", "mathvariant", u"normal");
98 if (bSmall)
99 assertXPathNoAttribute(pDoc, "/m:math/m:semantics/m:mrow/m:mi[3]", "mathvariant");
100 else
101 assertXPath(pDoc, "/m:math/m:semantics/m:mrow/m:mi[3]", "mathvariant", u"normal");
102 assertXPathNoAttribute(pDoc, "/m:math/m:semantics/m:mrow/m:mstyle[3]/m:mi[1]", "mathvariant");
103 assertXPathNoAttribute(pDoc, "/m:math/m:semantics/m:mrow/m:mi[4]", "mathvariant");
104 assertXPath(pDoc, "/m:math/m:semantics/m:mrow/m:mstyle[4]/m:mi[1]", "mathvariant", u"normal");
105 rDocShell.SetText(u""_ustr);
108 void MathMLExportTest::testTdf101022()
110 loadFromURL(u"private:factory/smath"_ustr);
111 SfxBaseModel* pModel = dynamic_cast<SfxBaseModel*>(mxComponent.get());
112 SmDocShell* pDocShell = static_cast<SmDocShell*>(pModel->GetObjectShell());
114 checkMathVariant(*pDocShell, false, true); // default mode 2
116 pDocShell->SetGreekCharStyle(1); // mode 1
117 checkMathVariant(*pDocShell, true, true);
119 pDocShell->SetGreekCharStyle(0); // mode 0
120 checkMathVariant(*pDocShell, false, false);
123 void MathMLExportTest::testMaj()
125 loadFromURL(u"private:factory/smath"_ustr);
126 SfxBaseModel* pModel = dynamic_cast<SfxBaseModel*>(mxComponent.get());
127 SmDocShell* pDocShell = static_cast<SmDocShell*>(pModel->GetObjectShell());
128 pDocShell->SetText(
129 u"maj to { \u0661 } from { \U0001EE0A = \u0660 } { \u0661 over \U0001EE0A }"_ustr);
130 save(u"MathML XML (Math)"_ustr);
131 xmlDocUniquePtr pDoc = parseXml(maTempFile);
132 CPPUNIT_ASSERT(pDoc);
133 assertXPath(pDoc, "/m:math/m:semantics/m:mrow/m:munderover/m:mo", "stretchy", u"false");
134 assertXPathContent(pDoc, "/m:math/m:semantics/m:mrow/m:munderover/m:mo", u"\U0001EEF0");
137 void MathMLExportTest::testHadd()
139 loadFromURL(u"private:factory/smath"_ustr);
140 SfxBaseModel* pModel = dynamic_cast<SfxBaseModel*>(mxComponent.get());
141 SmDocShell* pDocShell = static_cast<SmDocShell*>(pModel->GetObjectShell());
142 pDocShell->SetText(u"hadd to { \U0001EE4E } from { \U0001EE4E } \U0001EE4E"_ustr);
143 save(u"MathML XML (Math)"_ustr);
144 xmlDocUniquePtr pDoc = parseXml(maTempFile);
145 CPPUNIT_ASSERT(pDoc);
146 assertXPathContent(pDoc, "/m:math/m:semantics/m:mrow/m:munderover/m:mi", u"\U0001EEF1");
149 CPPUNIT_TEST_SUITE_REGISTRATION(MathMLExportTest);
151 CPPUNIT_PLUGIN_IMPLEMENT();
153 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */