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 #ifndef INCLUDED_STARMATH_QA_CPPUNIT_MOCK_VISITOR_HXX
11 #define INCLUDED_STARMATH_QA_CPPUNIT_MOCK_VISITOR_HXX
13 #include <cppunit/TestAssert.h>
14 #include <visitors.hxx>
16 /** Simple visitor for testing SmVisitor */
17 class MockVisitor
: public SmVisitor
20 virtual ~MockVisitor() {}
22 void Visit( SmTableNode
* pNode
) override
{
23 CPPUNIT_ASSERT_EQUAL_MESSAGE("SmTableNode should have type SmNodeType::Table",
24 SmNodeType::Table
, pNode
->GetType());
25 auto eTT
= pNode
->GetToken().eType
;
26 CPPUNIT_ASSERT_MESSAGE("The type of SmTableNode's token should be either TEND, TBINOM, or TSTACK",
27 eTT
== TEND
|| eTT
== TBINOM
|| eTT
== TSTACK
);
28 VisitChildren( pNode
);
31 void Visit( SmBraceNode
* pNode
) override
{
32 CPPUNIT_ASSERT_EQUAL_MESSAGE("SmBraceNode should have type SmNodeType::Brace",
33 SmNodeType::Brace
, pNode
->GetType());
34 VisitChildren( pNode
);
37 void Visit( SmBracebodyNode
* pNode
) override
{
38 CPPUNIT_ASSERT_EQUAL_MESSAGE("SmBracebodyNode should have type SmNodeType::Bracebody",
39 SmNodeType::Bracebody
, pNode
->GetType());
40 VisitChildren( pNode
);
43 void Visit( SmOperNode
* pNode
) override
{
44 CPPUNIT_ASSERT_EQUAL_MESSAGE("SmOperNode should have type SmNodeType::Oper",
45 SmNodeType::Oper
, pNode
->GetType());
46 VisitChildren( pNode
);
49 void Visit( SmAlignNode
* pNode
) override
{
50 CPPUNIT_ASSERT_EQUAL_MESSAGE("SmAlignNode should have type SmNodeType::Align",
51 SmNodeType::Align
, pNode
->GetType());
52 VisitChildren( pNode
);
55 void Visit( SmAttributNode
* pNode
) override
{
56 CPPUNIT_ASSERT_EQUAL_MESSAGE("SmAttributNode should have type SmNodeType::Attribut",
57 SmNodeType::Attribut
, pNode
->GetType());
58 VisitChildren( pNode
);
61 void Visit( SmFontNode
* pNode
) override
{
62 CPPUNIT_ASSERT_EQUAL_MESSAGE("SmFontNode should have type SmNodeType::Font",
63 SmNodeType::Font
, pNode
->GetType());
64 VisitChildren( pNode
);
67 void Visit( SmUnHorNode
* pNode
) override
{
68 CPPUNIT_ASSERT_EQUAL_MESSAGE("SmUnHorNode should have type SmNodeType::UnHor",
69 SmNodeType::UnHor
, pNode
->GetType());
70 VisitChildren( pNode
);
73 void Visit( SmBinHorNode
* pNode
) override
{
74 CPPUNIT_ASSERT_EQUAL_MESSAGE("SmBinHorNode should have type SmNodeType::BinHor",
75 SmNodeType::BinHor
, pNode
->GetType());
76 VisitChildren( pNode
);
79 void Visit( SmBinVerNode
* pNode
) override
{
80 CPPUNIT_ASSERT_EQUAL_MESSAGE("SmBinVerNode should have type SmNodeType::BinVer",
81 SmNodeType::BinVer
, pNode
->GetType());
82 VisitChildren( pNode
);
85 void Visit( SmBinDiagonalNode
* pNode
) override
{
86 CPPUNIT_ASSERT_EQUAL_MESSAGE("SmBinDiagonalNode should have type SmNodeType::BinDiagonal",
87 SmNodeType::BinDiagonal
, pNode
->GetType());
88 VisitChildren( pNode
);
91 void Visit( SmSubSupNode
* pNode
) override
{
92 CPPUNIT_ASSERT_EQUAL_MESSAGE("SmSubSupNode should have type SmNodeType::SubSup",
93 SmNodeType::SubSup
, pNode
->GetType());
94 VisitChildren( pNode
);
97 void Visit( SmMatrixNode
* pNode
) override
{
98 CPPUNIT_ASSERT_EQUAL_MESSAGE("SmMatrixNode should have type SmNodeType::Matrix",
99 SmNodeType::Matrix
, pNode
->GetType());
100 CPPUNIT_ASSERT_EQUAL_MESSAGE("SmMatrixNode's token should be of type TMATRIX",
101 TMATRIX
, pNode
->GetToken().eType
);
102 VisitChildren( pNode
);
105 void Visit( SmPlaceNode
* pNode
) override
{
106 CPPUNIT_ASSERT_EQUAL_MESSAGE("SmPlaceNode should have type SmNodeType::Place",
107 SmNodeType::Place
, pNode
->GetType());
110 void Visit( SmTextNode
* pNode
) override
{
111 CPPUNIT_ASSERT_EQUAL_MESSAGE("SmTextNode should have type SmNodeType::Text",
112 SmNodeType::Text
, pNode
->GetType());
115 void Visit( SmSpecialNode
* pNode
) override
{
116 CPPUNIT_ASSERT_EQUAL_MESSAGE("SmSpecialNode should have type SmNodeType::Special",
117 SmNodeType::Special
, pNode
->GetType());
120 void Visit( SmGlyphSpecialNode
* pNode
) override
{
121 CPPUNIT_ASSERT_EQUAL_MESSAGE("SmGlyphSpecialNode should have type SmNodeType::GlyphSpecial",
122 SmNodeType::GlyphSpecial
, pNode
->GetType());
125 void Visit( SmMathSymbolNode
* pNode
) override
{
126 CPPUNIT_ASSERT_MESSAGE("SmMathSymbolNode should have type SmNodeType::Math or SmNodeType::MathIdent",
127 pNode
->GetType() == SmNodeType::Math
|| pNode
->GetType() == SmNodeType::MathIdent
);
130 void Visit( SmBlankNode
* pNode
) override
{
131 CPPUNIT_ASSERT_EQUAL_MESSAGE("SmBlankNode should have type SmNodeType::Blank",
132 SmNodeType::Blank
, pNode
->GetType());
135 void Visit( SmErrorNode
* pNode
) override
{
136 CPPUNIT_ASSERT_EQUAL_MESSAGE("SmErrorNode should have type SmNodeType::Error",
137 SmNodeType::Error
, pNode
->GetType());
140 void Visit( SmLineNode
* pNode
) override
{
141 CPPUNIT_ASSERT_EQUAL_MESSAGE("SmLineNode should have type SmNodeType::Line",
142 SmNodeType::Line
, pNode
->GetType());
143 VisitChildren( pNode
);
146 void Visit( SmExpressionNode
* pNode
) override
{
147 CPPUNIT_ASSERT_EQUAL_MESSAGE("SmExpressionNode should have type SmNodeType::Expression",
148 SmNodeType::Expression
, pNode
->GetType());
149 VisitChildren( pNode
);
152 void Visit( SmPolyLineNode
* pNode
) override
{
153 CPPUNIT_ASSERT_EQUAL_MESSAGE("SmPolyLineNode should have type SmNodeType::PolyLine",
154 SmNodeType::PolyLine
, pNode
->GetType());
157 void Visit( SmRootNode
* pNode
) override
{
158 CPPUNIT_ASSERT_EQUAL_MESSAGE("SmRootNode should have type SmNodeType::Root",
159 SmNodeType::Root
, pNode
->GetType());
160 VisitChildren( pNode
);
163 void Visit( SmRootSymbolNode
* pNode
) override
{
164 CPPUNIT_ASSERT_EQUAL_MESSAGE("SmRootSymbolNode should have type SmNodeType::RootSymbol",
165 SmNodeType::RootSymbol
, pNode
->GetType());
168 void Visit( SmRectangleNode
* pNode
) override
{
169 CPPUNIT_ASSERT_EQUAL_MESSAGE("SmRectangleNode should have type SmNodeType::Rectangle",
170 SmNodeType::Rectangle
, pNode
->GetType());
173 void Visit( SmVerticalBraceNode
* pNode
) override
{
174 CPPUNIT_ASSERT_EQUAL_MESSAGE("SmVerticalBraceNode should have type SmNodeType::VerticalBrace",
175 SmNodeType::VerticalBrace
, pNode
->GetType());
176 VisitChildren( pNode
);
180 /** Auxiliary method for visiting the children of a pNode */
181 void VisitChildren( SmStructureNode
* pNode
) {
182 for (auto pChild
: *pNode
)
185 pChild
->Accept(this);
192 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */