Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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 : */
9 :
10 : #include <sal/config.h>
11 : #include <test/bootstrapfixture.hxx>
12 :
13 : #include <sfx2/docfile.hxx>
14 : #include <sfx2/docfilt.hxx>
15 : #include <sfx2/sfxmodelfactory.hxx>
16 :
17 : #include <document.hxx>
18 : #include <smdll.hxx>
19 :
20 : namespace {
21 :
22 : using namespace ::com::sun::star;
23 :
24 : typedef tools::SvRef<SmDocShell> SmDocShellRef;
25 :
26 9 : class Test : public test::BootstrapFixture
27 : {
28 : public:
29 : virtual void setUp() SAL_OVERRIDE;
30 : virtual void tearDown() SAL_OVERRIDE;
31 :
32 : void testSimple();
33 : void testNsPrefixMath();
34 : void testMaction();
35 :
36 2 : CPPUNIT_TEST_SUITE(Test);
37 1 : CPPUNIT_TEST(testSimple);
38 1 : CPPUNIT_TEST(testNsPrefixMath);
39 1 : CPPUNIT_TEST(testMaction);
40 5 : CPPUNIT_TEST_SUITE_END();
41 :
42 : private:
43 3 : void loadURL(const OUString &rURL)
44 : {
45 : // Cf.
46 : // filter/source/config/fragments/filters/MathML_XML__Math_.xcu
47 : SfxFilter* pFilter = new SfxFilter(MATHML_XML,
48 : OUString(),
49 6 : SfxFilterFlags::IMPORT | SfxFilterFlags::EXPORT | SfxFilterFlags::TEMPLATE,
50 : SotClipboardFormatId::STARCALC_8,
51 : "MathML 1.01",
52 : 0,
53 : OUString(),
54 : OUString(),
55 9 : "private:factory/smath*");
56 3 : pFilter->SetVersion(SOFFICE_FILEFORMAT_60);
57 :
58 9 : mxDocShell = new SmDocShell(SfxModelFlags::EMBEDDED_OBJECT |
59 6 : SfxModelFlags::DISABLE_EMBEDDED_SCRIPTS |
60 9 : SfxModelFlags::DISABLE_DOCUMENT_RECOVERY);
61 :
62 3 : SfxMedium* pSrcMed = new SfxMedium(rURL, STREAM_STD_READ);
63 3 : pSrcMed->SetFilter(pFilter);
64 3 : pSrcMed->UseInteractionHandler(false);
65 3 : bool bLoaded = mxDocShell->DoLoad(pSrcMed);
66 6 : CPPUNIT_ASSERT_MESSAGE(OUStringToOString("failed to load " + rURL, RTL_TEXTENCODING_UTF8).getStr(),
67 3 : bLoaded);
68 3 : }
69 :
70 : SmDocShellRef mxDocShell;
71 : };
72 :
73 3 : void Test::setUp()
74 : {
75 3 : BootstrapFixture::setUp();
76 3 : SmGlobals::ensure();
77 3 : }
78 :
79 3 : void Test::tearDown()
80 : {
81 3 : if (mxDocShell) mxDocShell->DoClose();
82 3 : BootstrapFixture::tearDown();
83 3 : }
84 :
85 1 : void Test::testSimple()
86 : {
87 1 : loadURL(getURLFromSrc("starmath/qa/extras/data/simple.mml"));
88 1 : OUString sExpected("left ( {italic \"a\" + italic \"b\"} right )^italic \"2\"");
89 1 : CPPUNIT_ASSERT_EQUAL_MESSAGE("loaded text", sExpected, mxDocShell->GetText());
90 1 : }
91 :
92 1 : void Test::testNsPrefixMath()
93 : {
94 1 : loadURL(getURLFromSrc("starmath/qa/extras/data/ns-prefix-math.mml"));
95 1 : OUString sExpected("left ( {italic \"a\" + italic \"b\"} right )^italic \"2\"");
96 1 : CPPUNIT_ASSERT_EQUAL_MESSAGE("loaded text", sExpected, mxDocShell->GetText());
97 1 : }
98 :
99 1 : void Test::testMaction()
100 : {
101 1 : loadURL(getURLFromSrc("starmath/qa/extras/data/maction.mml"));
102 1 : OUString sExpected("matrix {italic \"1\" ## italic \"2\" ## italic \"3\"}");
103 1 : CPPUNIT_ASSERT_EQUAL_MESSAGE("loaded text", sExpected, mxDocShell->GetText());
104 1 : }
105 :
106 1 : CPPUNIT_TEST_SUITE_REGISTRATION(Test);
107 :
108 : }
109 :
110 4 : CPPUNIT_PLUGIN_IMPLEMENT();
111 :
112 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|