android: Update app-specific/MIME type icons
[LibreOffice.git] / starmath / qa / extras / mmlexport-test.cxx
blobf2cfa2d238b911199d00fe3658de804ca08160b4
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("starmath/qa/extras/data/")
31 void testBlank();
32 void testTdf97049();
33 void testTdf101022();
35 CPPUNIT_TEST_SUITE(MathMLExportTest);
36 CPPUNIT_TEST(testBlank);
37 CPPUNIT_TEST(testTdf97049);
38 CPPUNIT_TEST(testTdf101022);
39 CPPUNIT_TEST_SUITE_END();
41 protected:
42 virtual void registerNamespaces(xmlXPathContextPtr& pXmlXPathCtx) override;
44 void checkMathVariant(SmDocShell& rDocShell, bool bCapital, bool bSmall);
47 void MathMLExportTest::registerNamespaces(xmlXPathContextPtr& pXmlXPathCtx)
49 xmlXPathRegisterNs(pXmlXPathCtx, BAD_CAST("m"), BAD_CAST("http://www.w3.org/1998/Math/MathML"));
52 void MathMLExportTest::testBlank()
54 mxComponent = loadFromDesktop("private:factory/smath");
55 SfxBaseModel* pModel = dynamic_cast<SfxBaseModel*>(mxComponent.get());
56 SmDocShell* pDocShell = static_cast<SmDocShell*>(pModel->GetObjectShell());
57 pDocShell->SetText("x`y~~z");
58 save("MathML XML (Math)");
59 xmlDocUniquePtr pDoc = parseXml(maTempFile);
60 CPPUNIT_ASSERT(pDoc);
61 assertXPath(pDoc, "/m:math/m:semantics/m:mrow/m:mspace[1]", "width", "0.5em");
62 assertXPath(pDoc, "/m:math/m:semantics/m:mrow/m:mspace[2]", "width", "4em");
65 void MathMLExportTest::testTdf97049()
67 mxComponent = loadFromDesktop("private:factory/smath");
68 SfxBaseModel* pModel = dynamic_cast<SfxBaseModel*>(mxComponent.get());
69 SmDocShell* pDocShell = static_cast<SmDocShell*>(pModel->GetObjectShell());
70 pDocShell->SetText("intd {{1 over x} dx}");
71 save("MathML XML (Math)");
72 xmlDocUniquePtr pDoc = parseXml(maTempFile);
73 CPPUNIT_ASSERT(pDoc);
74 assertXPath(pDoc, "/m:math/m:semantics/m:mrow/m:mo[1]", "stretchy", "true");
75 auto aContent = getXPathContent(pDoc, "/m:math/m:semantics/m:mrow/m:mo[1]");
76 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), aContent.getLength());
77 CPPUNIT_ASSERT_EQUAL(u'\x222B', aContent[0]);
80 void MathMLExportTest::checkMathVariant(SmDocShell& rDocShell, bool bCapital, bool bSmall)
82 rDocShell.SetText("%GAMMA %iGAMMA {ital %GAMMA} {nitalic %iGAMMA} "
83 "%gamma %igamma {ital %gamma} {nitalic %igamma}");
84 save("MathML XML (Math)");
85 xmlDocUniquePtr pDoc = parseXml(maTempFile);
86 CPPUNIT_ASSERT(pDoc);
87 if (bCapital)
88 assertXPathNoAttribute(pDoc, "/m:math/m:semantics/m:mrow/m:mi[1]", "mathvariant");
89 else
90 assertXPath(pDoc, "/m:math/m:semantics/m:mrow/m:mi[1]", "mathvariant", "normal");
91 assertXPathNoAttribute(pDoc, "/m:math/m:semantics/m:mrow/m:mstyle[1]/m:mi[1]", "mathvariant");
92 assertXPathNoAttribute(pDoc, "/m:math/m:semantics/m:mrow/m:mi[2]", "mathvariant");
93 assertXPath(pDoc, "/m:math/m:semantics/m:mrow/m:mstyle[2]/m:mi[1]", "mathvariant", "normal");
94 if (bSmall)
95 assertXPathNoAttribute(pDoc, "/m:math/m:semantics/m:mrow/m:mi[3]", "mathvariant");
96 else
97 assertXPath(pDoc, "/m:math/m:semantics/m:mrow/m:mi[3]", "mathvariant", "normal");
98 assertXPathNoAttribute(pDoc, "/m:math/m:semantics/m:mrow/m:mstyle[3]/m:mi[1]", "mathvariant");
99 assertXPathNoAttribute(pDoc, "/m:math/m:semantics/m:mrow/m:mi[4]", "mathvariant");
100 assertXPath(pDoc, "/m:math/m:semantics/m:mrow/m:mstyle[4]/m:mi[1]", "mathvariant", "normal");
101 rDocShell.SetText("");
104 void MathMLExportTest::testTdf101022()
106 mxComponent = loadFromDesktop("private:factory/smath");
107 SfxBaseModel* pModel = dynamic_cast<SfxBaseModel*>(mxComponent.get());
108 SmDocShell* pDocShell = static_cast<SmDocShell*>(pModel->GetObjectShell());
110 checkMathVariant(*pDocShell, false, true); // default mode 2
112 pDocShell->SetGreekCharStyle(1); // mode 1
113 checkMathVariant(*pDocShell, true, true);
115 pDocShell->SetGreekCharStyle(0); // mode 0
116 checkMathVariant(*pDocShell, false, false);
119 CPPUNIT_TEST_SUITE_REGISTRATION(MathMLExportTest);
121 CPPUNIT_PLUGIN_IMPLEMENT();
123 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */