1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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/.
10 #include <sal/config.h>
11 #include <test/unoapi_test.hxx>
13 #include <sfx2/sfxbasemodel.hxx>
15 #include <document.hxx>
18 using namespace ::com::sun::star
;
20 class Test
: public UnoApiTest
24 : UnoApiTest("starmath/qa/extras/data/")
30 void testNsPrefixMath();
38 void testMathmlEntities();
40 CPPUNIT_TEST_SUITE(Test
);
41 CPPUNIT_TEST(testColor
);
42 CPPUNIT_TEST(testSimple
);
43 CPPUNIT_TEST(testNsPrefixMath
);
44 CPPUNIT_TEST(testMaction
);
45 CPPUNIT_TEST(testMspace
);
46 CPPUNIT_TEST(testtdf99556
);
47 CPPUNIT_TEST(testTdf103430
);
48 CPPUNIT_TEST(testTdf103500
);
49 CPPUNIT_TEST(testTdf137008
);
50 CPPUNIT_TEST(testTdf151842
);
51 CPPUNIT_TEST(testMathmlEntities
);
52 CPPUNIT_TEST_SUITE_END();
55 void Test::testColor()
57 loadFromURL(u
"color.mml");
58 SfxBaseModel
* pModel
= dynamic_cast<SfxBaseModel
*>(mxComponent
.get());
59 SmDocShell
* pDocShell
= static_cast<SmDocShell
*>(pModel
->GetObjectShell());
60 CPPUNIT_ASSERT_EQUAL(OUString("{ color black b"
79 " color rgb 220 20 61 x }"),
80 pDocShell
->GetText());
83 void Test::testSimple()
85 loadFromURL(u
"simple.mml");
86 SfxBaseModel
* pModel
= dynamic_cast<SfxBaseModel
*>(mxComponent
.get());
87 SmDocShell
* pDocShell
= static_cast<SmDocShell
*>(pModel
->GetObjectShell());
88 CPPUNIT_ASSERT_EQUAL_MESSAGE("loaded text", OUString("left ( { a + b } right ) ^ 2"),
89 pDocShell
->GetText());
92 void Test::testNsPrefixMath()
94 loadFromURL(u
"ns-prefix-math.mml");
95 SfxBaseModel
* pModel
= dynamic_cast<SfxBaseModel
*>(mxComponent
.get());
96 SmDocShell
* pDocShell
= static_cast<SmDocShell
*>(pModel
->GetObjectShell());
97 CPPUNIT_ASSERT_EQUAL_MESSAGE("loaded text", OUString("left ( { a + b } right ) ^ 2"),
98 pDocShell
->GetText());
101 void Test::testMaction()
103 loadFromURL(u
"maction.mml");
104 SfxBaseModel
* pModel
= dynamic_cast<SfxBaseModel
*>(mxComponent
.get());
105 SmDocShell
* pDocShell
= static_cast<SmDocShell
*>(pModel
->GetObjectShell());
106 CPPUNIT_ASSERT_EQUAL_MESSAGE("loaded text", OUString("matrix{ 1 ## 2 ## 3 }"),
107 pDocShell
->GetText());
110 void Test::testMspace()
112 loadFromURL(u
"mspace.mml");
113 SfxBaseModel
* pModel
= dynamic_cast<SfxBaseModel
*>(mxComponent
.get());
114 SmDocShell
* pDocShell
= static_cast<SmDocShell
*>(pModel
->GetObjectShell());
115 CPPUNIT_ASSERT_EQUAL(OUString("{ a b ~ c ~~``` d }"), pDocShell
->GetText());
118 void Test::testtdf99556()
120 loadFromURL(u
"tdf99556-1.mml");
121 SfxBaseModel
* pModel
= dynamic_cast<SfxBaseModel
*>(mxComponent
.get());
122 SmDocShell
* pDocShell
= static_cast<SmDocShell
*>(pModel
->GetObjectShell());
123 CPPUNIT_ASSERT_EQUAL_MESSAGE("loaded text", OUString("sqrt { }"), pDocShell
->GetText());
126 void Test::testTdf103430()
128 loadFromURL(u
"tdf103430.mml");
129 SfxBaseModel
* pModel
= dynamic_cast<SfxBaseModel
*>(mxComponent
.get());
130 SmDocShell
* pDocShell
= static_cast<SmDocShell
*>(pModel
->GetObjectShell());
131 CPPUNIT_ASSERT_EQUAL(
132 OUString("{ frac { { nitalic d ^ 2 nitalic color blue y } } { { color dvip "
133 "apricot nitalic d font sans bold italic color red x } } }"),
134 pDocShell
->GetText());
137 void Test::testTdf103500()
139 loadFromURL(u
"tdf103500.mml");
140 SfxBaseModel
* pModel
= dynamic_cast<SfxBaseModel
*>(mxComponent
.get());
141 SmDocShell
* pDocShell
= static_cast<SmDocShell
*>(pModel
->GetObjectShell());
142 CPPUNIT_ASSERT_EQUAL(
143 OUString("{ { int csup b csub a { { frac { 1 } { x } } ` nitalic d x } } = { "
144 "intd csup b csub a { { frac { 1 } { y } } ` nitalic d y } } }"),
145 pDocShell
->GetText());
148 void Test::testTdf137008()
150 // Without the fix in place, this test would have crashed
151 loadFromURL(u
"tdf137008.mml");
152 SfxBaseModel
* pModel
= dynamic_cast<SfxBaseModel
*>(mxComponent
.get());
153 SmDocShell
* pDocShell
= static_cast<SmDocShell
*>(pModel
->GetObjectShell());
154 CPPUNIT_ASSERT_EQUAL(OUString("matrix{ { } # ## # }"), pDocShell
->GetText());
157 void Test::testTdf151842()
159 // Without the fix in place, this test would have crashed
160 loadFromURL(u
"tdf151842.odf");
161 SfxBaseModel
* pModel
= dynamic_cast<SfxBaseModel
*>(mxComponent
.get());
162 SmDocShell
* pDocShell
= static_cast<SmDocShell
*>(pModel
->GetObjectShell());
163 CPPUNIT_ASSERT_EQUAL(OUString("test"), pDocShell
->GetText());
164 SmFormat aFormat
= pDocShell
->GetFormat();
166 // Without the fix in place, this test would have failed with
169 CPPUNIT_ASSERT_EQUAL(tools::Long(4233), aFormat
.GetBaseSize().Height());
172 void Test::testMathmlEntities()
174 loadFromURL(u
"mthmlentities.mml");
175 SfxBaseModel
* pModel
= dynamic_cast<SfxBaseModel
*>(mxComponent
.get());
176 SmDocShell
* pDocShell
= static_cast<SmDocShell
*>(pModel
->GetObjectShell());
177 CPPUNIT_ASSERT_EQUAL(OUString(u
"{ \u03C3 \u221E \u221E \u03C3 }"), pDocShell
->GetText());
180 CPPUNIT_TEST_SUITE_REGISTRATION(Test
);
182 CPPUNIT_PLUGIN_IMPLEMENT();
184 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */