summaryrefslogtreecommitdiff
path: root/starmath/qa
diff options
context:
space:
mode:
authorTakeshi Abe <tabe@fixedpoint.jp>2016-07-28 09:03:59 +0900
committerCaolán McNamara <caolanm@redhat.com>2016-07-31 20:20:25 +0000
commitff4217e9e4f90a8dd09e635a35665a64846b4505 (patch)
tree7da51246ddefca02798ad460e0bf5a9387aae3bd /starmath/qa
parentd1d1109fd7bd5bdaa9aa09feeca9f15bf28aa57e (diff)
tdf#101022 Export Greek symbol to MathML with correct mathvariant
In StarMath notation "{ital %GAMMA}" is recognized as italic, and "{nitalic %iGAMMA}" is non-italic. That is, the ital/nitalic directive takes priority over special characters' flavor. On the other hand, in MathML a mathvariant attribute given in <mi> overwrites inherited value. This does not handle "bold-italic" case etc. yet. Change-Id: I9c72dc4472f8cec553417d516d9d82aebd43d15c Reviewed-on: https://gerrit.libreoffice.org/27604 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Caolán McNamara <caolanm@redhat.com> Tested-by: Caolán McNamara <caolanm@redhat.com>
Diffstat (limited to 'starmath/qa')
-rw-r--r--starmath/qa/extras/mmlexport-test.cxx130
1 files changed, 130 insertions, 0 deletions
diff --git a/starmath/qa/extras/mmlexport-test.cxx b/starmath/qa/extras/mmlexport-test.cxx
new file mode 100644
index 000000000000..ce1a4675d0fc
--- /dev/null
+++ b/starmath/qa/extras/mmlexport-test.cxx
@@ -0,0 +1,130 @@
+/* -*- 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 <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 "node.hxx"
+#include "parse.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 testTdf101022();
+
+ CPPUNIT_TEST_SUITE(MathMLExportTest);
+ CPPUNIT_TEST(testTdf101022);
+ CPPUNIT_TEST_SUITE_END();
+
+protected:
+ virtual void registerNamespaces(xmlXPathContextPtr &pXmlXPathCtx) override;
+
+private:
+ xmlDocPtr 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)
+ mxDocShell->DoClose();
+ BootstrapFixture::tearDown();
+}
+
+void MathMLExportTest::registerNamespaces(xmlXPathContextPtr &pXmlXPathCtx)
+{
+ xmlXPathRegisterNs(pXmlXPathCtx, BAD_CAST("m"), BAD_CAST("http://www.w3.org/1998/Math/MathML"));
+}
+
+xmlDocPtr MathMLExportTest::exportAndParse()
+{
+ utl::TempFile aTempFile;
+ aTempFile.EnableKillingFile();
+ SfxMedium aStoreMedium(aTempFile.GetURL(), STREAM_STD_WRITE);
+ std::shared_ptr<const SfxFilter> pExportFilter = SfxFilter::GetFilterByName(MATHML_XML);
+ aStoreMedium.SetFilter(pExportFilter);
+ CPPUNIT_ASSERT(mxDocShell->ConvertTo(aStoreMedium));
+ aStoreMedium.Commit();
+ xmlDocPtr pDoc = parseXml(aTempFile);
+ CPPUNIT_ASSERT(pDoc);
+ return pDoc;
+}
+
+void MathMLExportTest::testTdf101022()
+{
+#define CHECK_MATHVARIANT(capital, small) do \
+ { \
+ mxDocShell->SetText("%GAMMA %iGAMMA {ital %GAMMA} {nitalic %iGAMMA} " \
+ "%gamma %igamma {ital %gamma} {nitalic %igamma}"); \
+ xmlDocPtr 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, false); // default mode 0
+
+ mxDocShell->SetGreekCharStyle(1); // mode 1
+ CHECK_MATHVARIANT(true, true);
+
+ mxDocShell->SetGreekCharStyle(2); // mode 2
+ CHECK_MATHVARIANT(false, true);
+
+#undef CHECK_MATHVARIANT
+}
+
+CPPUNIT_TEST_SUITE_REGISTRATION(MathMLExportTest);
+
+}
+
+CPPUNIT_PLUGIN_IMPLEMENT();
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */