nss: upgrade to release 3.73
[LibreOffice.git] / starmath / qa / cppunit / test_node.cxx
blobe543ac04027c6a8e790d7b4e77fc19c1adcf3152
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 <o3tl/cppunittraitshelper.hxx>
14 #include <sfx2/sfxmodelfactory.hxx>
15 #include <vcl/virdev.hxx>
17 #include <document.hxx>
18 #include <smdll.hxx>
19 #include <node.hxx>
20 #include <parse.hxx>
21 #include <utility.hxx>
23 #include <memory>
25 namespace {
27 using namespace ::com::sun::star;
29 typedef tools::SvRef<SmDocShell> SmDocShellRef;
31 class NodeTest : public test::BootstrapFixture
33 public:
34 virtual void setUp() override;
35 virtual void tearDown() override;
37 private:
38 void testTdf47813();
39 void testTdf52225();
41 CPPUNIT_TEST_SUITE(NodeTest);
42 CPPUNIT_TEST(testTdf47813);
43 CPPUNIT_TEST(testTdf52225);
44 CPPUNIT_TEST_SUITE_END();
46 SmDocShellRef mxDocShell;
49 void NodeTest::setUp()
51 BootstrapFixture::setUp();
52 SmGlobals::ensure();
53 mxDocShell = new SmDocShell(SfxModelFlags::EMBEDDED_OBJECT |
54 SfxModelFlags::DISABLE_EMBEDDED_SCRIPTS |
55 SfxModelFlags::DISABLE_DOCUMENT_RECOVERY);
58 void NodeTest::tearDown()
60 if (mxDocShell.is())
61 mxDocShell->DoClose();
62 BootstrapFixture::tearDown();
65 void NodeTest::testTdf47813()
67 SmParser aParser;
68 #define MATRIX "matrix {-2#33##4#-5##6,0#7}"
69 auto pNodeA = aParser.Parse(MATRIX);
70 auto pNodeC = aParser.Parse("alignc " MATRIX);
71 auto pNodeL = aParser.Parse("alignl " MATRIX);
72 auto pNodeR = aParser.Parse("alignr " MATRIX);
73 #undef MATRIX
74 ScopedVclPtrInstance<VirtualDevice> pOutputDevice;
75 SmFormat aFmt;
76 pNodeA->Prepare(aFmt, *mxDocShell, 0);
77 pNodeA->Arrange(*pOutputDevice, aFmt);
78 pNodeC->Prepare(aFmt, *mxDocShell, 0);
79 pNodeC->Arrange(*pOutputDevice, aFmt);
80 pNodeL->Prepare(aFmt, *mxDocShell, 0);
81 pNodeL->Arrange(*pOutputDevice, aFmt);
82 pNodeR->Prepare(aFmt, *mxDocShell, 0);
83 pNodeR->Arrange(*pOutputDevice, aFmt);
84 tools::Long nWidthA = pNodeA->GetRect().GetWidth();
85 tools::Long nWidthC = pNodeC->GetRect().GetWidth();
86 tools::Long nWidthL = pNodeL->GetRect().GetWidth();
87 tools::Long nWidthR = pNodeR->GetRect().GetWidth();
88 CPPUNIT_ASSERT_DOUBLES_EQUAL(1.0, nWidthC/static_cast<double>(nWidthA), 0.01);
89 // these values appear to change slightly with display scaling
90 CPPUNIT_ASSERT_DOUBLES_EQUAL(1.0, nWidthL/static_cast<double>(nWidthA), 0.03);
91 CPPUNIT_ASSERT_DOUBLES_EQUAL(1.0, nWidthR/static_cast<double>(nWidthA), 0.03);
94 void NodeTest::testTdf52225()
96 #define CHECK_GREEK_SYMBOL(text, code, bItalic) do { \
97 mxDocShell->SetText(text); \
98 const SmTableNode *pTree= mxDocShell->GetFormulaTree(); \
99 CPPUNIT_ASSERT_EQUAL(size_t(1), pTree->GetNumSubNodes()); \
100 const SmNode *pLine = pTree->GetSubNode(0); \
101 CPPUNIT_ASSERT(pLine); \
102 CPPUNIT_ASSERT_EQUAL(SmNodeType::Line, pLine->GetType()); \
103 CPPUNIT_ASSERT_EQUAL(size_t(1), pLine->GetNumSubNodes()); \
104 const SmNode *pNode = pLine->GetSubNode(0); \
105 CPPUNIT_ASSERT(pNode); \
106 CPPUNIT_ASSERT_EQUAL(SmNodeType::Special, pNode->GetType()); \
107 const SmSpecialNode *pSn = static_cast<const SmSpecialNode *>(pNode); \
108 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), pSn->GetText().getLength()); \
109 CPPUNIT_ASSERT_EQUAL(code, pSn->GetText()[0]); \
110 CPPUNIT_ASSERT_EQUAL(OUString(text), pSn->GetToken().aText); \
111 CPPUNIT_ASSERT_EQUAL(bItalic, IsItalic(pSn->GetFont())); \
112 } while (false)
114 SmFormat aFormat = mxDocShell->GetFormat();
115 CPPUNIT_ASSERT_EQUAL(sal_Int16(2), aFormat.GetGreekCharStyle()); // default format = 2
116 CHECK_GREEK_SYMBOL("%ALPHA", u'\x0391', false);
117 CHECK_GREEK_SYMBOL("%iALPHA", u'\x0391', true);
118 CHECK_GREEK_SYMBOL("%alpha", u'\x03b1', true);
119 CHECK_GREEK_SYMBOL("%ialpha", u'\x03b1', true);
121 // mode 1
122 aFormat.SetGreekCharStyle(1);
123 mxDocShell->SetFormat(aFormat);
124 CHECK_GREEK_SYMBOL("%BETA", u'\x0392', true);
125 CHECK_GREEK_SYMBOL("%iBETA", u'\x0392', true);
126 CHECK_GREEK_SYMBOL("%beta", u'\x03b2', true);
127 CHECK_GREEK_SYMBOL("%ibeta", u'\x03b2', true);
129 // mode 0
130 aFormat.SetGreekCharStyle(0);
131 mxDocShell->SetFormat(aFormat);
132 CHECK_GREEK_SYMBOL("%GAMMA", u'\x0393', false);
133 CHECK_GREEK_SYMBOL("%iGAMMA", u'\x0393', true);
134 CHECK_GREEK_SYMBOL("%gamma", u'\x03b3', false);
135 CHECK_GREEK_SYMBOL("%igamma", u'\x03b3', true);
137 #undef CHECK_GREEK_SYMBOL
140 CPPUNIT_TEST_SUITE_REGISTRATION(NodeTest);
144 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */