android: Update app-specific/MIME type icons
[LibreOffice.git] / starmath / qa / cppunit / test_parse.cxx
blob2171cde80e56aa8bf58d1323efbf58b913992dfa
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/bootstrapfixture.hxx>
13 #include <sfx2/sfxmodelfactory.hxx>
15 #include <document.hxx>
16 #include <smdll.hxx>
17 #include <node.hxx>
18 #include <parse5.hxx>
20 #include <memory>
22 namespace {
24 using namespace ::com::sun::star;
26 typedef tools::SvRef<SmDocShell> SmDocShellRef;
28 class ParseTest : public test::BootstrapFixture
30 public:
31 virtual void setUp() override;
32 virtual void tearDown() override;
34 private:
35 void testMinus();
36 void testNospace();
38 CPPUNIT_TEST_SUITE(ParseTest);
39 CPPUNIT_TEST(testMinus);
40 CPPUNIT_TEST(testNospace);
41 CPPUNIT_TEST_SUITE_END();
43 SmDocShellRef mxDocShell;
46 void ParseTest::setUp()
48 BootstrapFixture::setUp();
49 SmGlobals::ensure();
50 mxDocShell = new SmDocShell(SfxModelFlags::EMBEDDED_OBJECT |
51 SfxModelFlags::DISABLE_EMBEDDED_SCRIPTS |
52 SfxModelFlags::DISABLE_DOCUMENT_RECOVERY);
55 void ParseTest::tearDown()
57 if (mxDocShell.is())
58 mxDocShell->DoClose();
59 BootstrapFixture::tearDown();
63 * This shows that input "-" is recognized as a separate token even when
64 * it is immediately followed by a number.
66 void ParseTest::testMinus()
68 auto pNode = SmParser5().Parse("-1.2");
69 CPPUNIT_ASSERT_EQUAL(size_t(1), pNode->GetNumSubNodes());
70 const SmNode *pNode0 = pNode->GetSubNode(0);
71 CPPUNIT_ASSERT(pNode0);
72 CPPUNIT_ASSERT_EQUAL(SmNodeType::Line, pNode0->GetType());
73 CPPUNIT_ASSERT_EQUAL(size_t(1), pNode0->GetNumSubNodes());
74 const SmNode *pNode00 = pNode0->GetSubNode(0);
75 CPPUNIT_ASSERT(pNode00);
76 CPPUNIT_ASSERT_EQUAL(SmNodeType::UnHor, pNode00->GetType());
77 CPPUNIT_ASSERT_EQUAL(size_t(2), pNode00->GetNumSubNodes());
78 const SmNode *pNode000 = pNode00->GetSubNode(0);
79 CPPUNIT_ASSERT(pNode000);
80 CPPUNIT_ASSERT_EQUAL(SmNodeType::Math, pNode000->GetType());
81 // GetText() vs GetToken().aText
82 CPPUNIT_ASSERT_EQUAL(OUString(MS_MINUS),
83 static_cast<const SmMathSymbolNode *>(pNode000)->GetText());
84 CPPUNIT_ASSERT_EQUAL(OUString("-"),
85 static_cast<const SmMathSymbolNode *>(pNode000)->GetToken().aText);
86 const SmNode *pNode001 = pNode00->GetSubNode(1);
87 CPPUNIT_ASSERT(pNode001);
88 CPPUNIT_ASSERT_EQUAL(SmNodeType::Text, pNode001->GetType());
89 // GetText() vs GetToken().aText
90 CPPUNIT_ASSERT(static_cast<const SmTextNode *>(pNode001)->GetText().isEmpty());
91 CPPUNIT_ASSERT_EQUAL(OUString("1.2"),
92 static_cast<const SmTextNode *>(pNode001)->GetToken().aText);
96 * This shows that "nospace" turns off the expression's IsUseExtraSpaces(),
97 * but leaves its descendants' flag on.
99 void ParseTest::testNospace()
101 auto pNode = SmParser5().Parse("nospace{ nitalic d {F(x) G(x)} }");
102 CPPUNIT_ASSERT_EQUAL(size_t(1), pNode->GetNumSubNodes());
103 const SmNode *pNode0 = pNode->GetSubNode(0);
104 CPPUNIT_ASSERT(pNode0);
105 CPPUNIT_ASSERT_EQUAL(SmNodeType::Line, pNode0->GetType());
106 CPPUNIT_ASSERT_EQUAL(size_t(1), pNode0->GetNumSubNodes());
107 const SmNode *pNode00 = pNode0->GetSubNode(0);
108 CPPUNIT_ASSERT(pNode00);
109 CPPUNIT_ASSERT_EQUAL(SmNodeType::Expression, pNode00->GetType());
110 CPPUNIT_ASSERT(!static_cast<const SmExpressionNode *>(pNode00)->IsUseExtraSpaces());
111 CPPUNIT_ASSERT_EQUAL(size_t(2), pNode00->GetNumSubNodes());
112 const SmNode *pNode000 = pNode00->GetSubNode(0);
113 CPPUNIT_ASSERT(pNode000);
114 CPPUNIT_ASSERT_EQUAL(SmNodeType::Font, pNode000->GetType());
115 CPPUNIT_ASSERT_EQUAL(OUString("nitalic"),
116 static_cast<const SmFontNode *>(pNode000)->GetToken().aText);
117 const SmNode *pNode001 = pNode00->GetSubNode(1);
118 CPPUNIT_ASSERT(pNode001);
119 CPPUNIT_ASSERT_EQUAL(SmNodeType::Expression, pNode001->GetType());
120 CPPUNIT_ASSERT(static_cast<const SmExpressionNode *>(pNode001)->IsUseExtraSpaces());
121 CPPUNIT_ASSERT_EQUAL(size_t(2), pNode00->GetNumSubNodes());
124 CPPUNIT_TEST_SUITE_REGISTRATION(ParseTest);
128 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */