[Libreoffice-commits] core.git: starmath/inc starmath/qa starmath/source

Takeshi Abe tabe at fixedpoint.jp
Fri Nov 28 04:10:37 PST 2014


 starmath/inc/visitors.hxx                       |   39 ----
 starmath/qa/cppunit/mock-visitor.hxx            |  207 ++++++++++++++++++++++++
 starmath/qa/cppunit/test_nodetotextvisitors.cxx |   17 +
 starmath/source/visitors.cxx                    |  183 ---------------------
 4 files changed, 224 insertions(+), 222 deletions(-)

New commits:
commit e2c7b93744e61f3a7a9a04056a95894c9e888db8
Author: Takeshi Abe <tabe at fixedpoint.jp>
Date:   Fri Nov 28 17:43:57 2014 +0900

    recycle SmVisitorTest for unit test
    
    i.e. move unused SmVisitorTest to qa/ as MockVisitor, and
    call it in existing test cases.
    
    Change-Id: I20dc45537f7a0e325e952724607e695f3b3da21f
    Reviewed-on: https://gerrit.libreoffice.org/13165
    Reviewed-by: Caolán McNamara <caolanm at redhat.com>
    Tested-by: Caolán McNamara <caolanm at redhat.com>

diff --git a/starmath/inc/visitors.hxx b/starmath/inc/visitors.hxx
index 9a1ebb1..cdb6595 100644
--- a/starmath/inc/visitors.hxx
+++ b/starmath/inc/visitors.hxx
@@ -53,45 +53,6 @@ protected:
     ~SmVisitor() {}
 };
 
-/** Simple visitor for testing SmVisitor */
-class SmVisitorTest : public SmVisitor
-{
-public:
-    virtual ~SmVisitorTest() {}
-    void Visit( SmTableNode* pNode ) SAL_OVERRIDE;
-    void Visit( SmBraceNode* pNode ) SAL_OVERRIDE;
-    void Visit( SmBracebodyNode* pNode ) SAL_OVERRIDE;
-    void Visit( SmOperNode* pNode ) SAL_OVERRIDE;
-    void Visit( SmAlignNode* pNode ) SAL_OVERRIDE;
-    void Visit( SmAttributNode* pNode ) SAL_OVERRIDE;
-    void Visit( SmFontNode* pNode ) SAL_OVERRIDE;
-    void Visit( SmUnHorNode* pNode ) SAL_OVERRIDE;
-    void Visit( SmBinHorNode* pNode ) SAL_OVERRIDE;
-    void Visit( SmBinVerNode* pNode ) SAL_OVERRIDE;
-    void Visit( SmBinDiagonalNode* pNode ) SAL_OVERRIDE;
-    void Visit( SmSubSupNode* pNode ) SAL_OVERRIDE;
-    void Visit( SmMatrixNode* pNode ) SAL_OVERRIDE;
-    void Visit( SmPlaceNode* pNode ) SAL_OVERRIDE;
-    void Visit( SmTextNode* pNode ) SAL_OVERRIDE;
-    void Visit( SmSpecialNode* pNode ) SAL_OVERRIDE;
-    void Visit( SmGlyphSpecialNode* pNode ) SAL_OVERRIDE;
-    void Visit( SmMathSymbolNode* pNode ) SAL_OVERRIDE;
-    void Visit( SmBlankNode* pNode ) SAL_OVERRIDE;
-    void Visit( SmErrorNode* pNode ) SAL_OVERRIDE;
-    void Visit( SmLineNode* pNode ) SAL_OVERRIDE;
-    void Visit( SmExpressionNode* pNode ) SAL_OVERRIDE;
-    void Visit( SmPolyLineNode* pNode ) SAL_OVERRIDE;
-    void Visit( SmRootNode* pNode ) SAL_OVERRIDE;
-    void Visit( SmRootSymbolNode* pNode ) SAL_OVERRIDE;
-    void Visit( SmDynIntegralNode* pNode ) SAL_OVERRIDE;
-    void Visit( SmDynIntegralSymbolNode* pNode ) SAL_OVERRIDE;
-    void Visit( SmRectangleNode* pNode ) SAL_OVERRIDE;
-    void Visit( SmVerticalBraceNode* pNode ) SAL_OVERRIDE;
-private:
-    /** Auxiliary method for visiting the children of a pNode */
-    void VisitChildren( SmNode* pNode );
-};
-
 // SmDefaultingVisitor
 
 
diff --git a/starmath/qa/cppunit/mock-visitor.hxx b/starmath/qa/cppunit/mock-visitor.hxx
new file mode 100644
index 0000000..3284f0f
--- /dev/null
+++ b/starmath/qa/cppunit/mock-visitor.hxx
@@ -0,0 +1,207 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#ifndef INCLUDED_STARMATH_QA_CPPUNIT_MOCK_VISITOR_HXX
+#define INCLUDED_STARMATH_QA_CPPUNIT_MOCK_VISITOR_HXX
+
+#include <cppunit/TestAssert.h>
+#include "visitors.hxx"
+
+/** Simple visitor for testing SmVisitor */
+class MockVisitor : public SmVisitor
+{
+public:
+    virtual ~MockVisitor() {}
+
+    void Visit( SmTableNode* pNode ) SAL_OVERRIDE {
+        CPPUNIT_ASSERT_EQUAL_MESSAGE("SmTableNode should have type NTABLE",
+                                     pNode->GetType(), NTABLE);
+        VisitChildren( pNode );
+    }
+
+    void Visit( SmBraceNode* pNode ) SAL_OVERRIDE {
+        CPPUNIT_ASSERT_EQUAL_MESSAGE("SmBraceNode should have type NBRACE",
+                                     pNode->GetType(), NBRACE);
+        VisitChildren( pNode );
+    }
+
+    void Visit( SmBracebodyNode* pNode ) SAL_OVERRIDE {
+        CPPUNIT_ASSERT_EQUAL_MESSAGE("SmBracebodyNode should have type NBRACEBODY",
+                                     pNode->GetType(), NBRACEBODY);
+        VisitChildren( pNode );
+    }
+
+    void Visit( SmOperNode* pNode ) SAL_OVERRIDE {
+        CPPUNIT_ASSERT_EQUAL_MESSAGE("SmOperNode should have type NOPER",
+                                     pNode->GetType(), NOPER);
+        VisitChildren( pNode );
+    }
+
+    void Visit( SmAlignNode* pNode ) SAL_OVERRIDE {
+        CPPUNIT_ASSERT_EQUAL_MESSAGE("SmAlignNode should have type NALIGN",
+                                     pNode->GetType(), NALIGN);
+        VisitChildren( pNode );
+    }
+
+    void Visit( SmAttributNode* pNode ) SAL_OVERRIDE {
+        CPPUNIT_ASSERT_EQUAL_MESSAGE("SmAttributNode should have type NATTRIBUT",
+                                     pNode->GetType(), NATTRIBUT);
+        VisitChildren( pNode );
+    }
+
+    void Visit( SmFontNode* pNode ) SAL_OVERRIDE {
+        CPPUNIT_ASSERT_EQUAL_MESSAGE("SmFontNode should have type NFONT",
+                                     pNode->GetType(), NFONT);
+        VisitChildren( pNode );
+    }
+
+    void Visit( SmUnHorNode* pNode ) SAL_OVERRIDE {
+        CPPUNIT_ASSERT_EQUAL_MESSAGE("SmUnHorNode should have type NUNHOR",
+                                     pNode->GetType(), NUNHOR);
+        VisitChildren( pNode );
+    }
+
+    void Visit( SmBinHorNode* pNode ) SAL_OVERRIDE {
+        CPPUNIT_ASSERT_EQUAL_MESSAGE("SmBinHorNode should have type NBINHOR",
+                                     pNode->GetType(), NBINHOR);
+        VisitChildren( pNode );
+    }
+
+    void Visit( SmBinVerNode* pNode ) SAL_OVERRIDE {
+        CPPUNIT_ASSERT_EQUAL_MESSAGE("SmBinVerNode should have type NBINVER",
+                                     pNode->GetType(), NBINVER);
+        VisitChildren( pNode );
+    }
+
+    void Visit( SmBinDiagonalNode* pNode ) SAL_OVERRIDE {
+        CPPUNIT_ASSERT_EQUAL_MESSAGE("SmBinDiagonalNode should have type NBINDIAGONAL",
+                                     pNode->GetType(), NBINDIAGONAL);
+        VisitChildren( pNode );
+    }
+
+    void Visit( SmSubSupNode* pNode ) SAL_OVERRIDE {
+        CPPUNIT_ASSERT_EQUAL_MESSAGE("SmSubSupNode should have type NSUBSUP",
+                                     pNode->GetType(), NSUBSUP);
+        VisitChildren( pNode );
+    }
+
+    void Visit( SmMatrixNode* pNode ) SAL_OVERRIDE {
+        CPPUNIT_ASSERT_EQUAL_MESSAGE("SmMatrixNode should have type NMATRIX",
+                                     pNode->GetType(), NMATRIX);
+        VisitChildren( pNode );
+    }
+
+    void Visit( SmPlaceNode* pNode ) SAL_OVERRIDE {
+        CPPUNIT_ASSERT_EQUAL_MESSAGE("SmPlaceNode should have type NPLACE",
+                                     pNode->GetType(), NPLACE);
+        VisitChildren( pNode );
+    }
+
+    void Visit( SmTextNode* pNode ) SAL_OVERRIDE {
+        CPPUNIT_ASSERT_EQUAL_MESSAGE("SmTextNode should have type NTEXT",
+                                     pNode->GetType(), NTEXT);
+        VisitChildren( pNode );
+    }
+
+    void Visit( SmSpecialNode* pNode ) SAL_OVERRIDE {
+        CPPUNIT_ASSERT_EQUAL_MESSAGE("SmSpecialNode should have type NSPECIAL",
+                                     pNode->GetType(), NSPECIAL);
+        VisitChildren( pNode );
+    }
+
+    void Visit( SmGlyphSpecialNode* pNode ) SAL_OVERRIDE {
+        CPPUNIT_ASSERT_EQUAL_MESSAGE("SmGlyphSpecialNode should have type NGLYPH_SPECIAL",
+                                     pNode->GetType(), NGLYPH_SPECIAL);
+        VisitChildren( pNode );
+    }
+
+    void Visit( SmMathSymbolNode* pNode ) SAL_OVERRIDE {
+        CPPUNIT_ASSERT_MESSAGE("SmMathSymbolNode should have type NMATH or NMATHIDENT",
+                               pNode->GetType() == NMATH || pNode->GetType() == NMATHIDENT);
+        VisitChildren( pNode );
+    }
+
+    void Visit( SmBlankNode* pNode ) SAL_OVERRIDE {
+        CPPUNIT_ASSERT_EQUAL_MESSAGE("SmBlankNode should have type NBLANK",
+                                     pNode->GetType(), NBLANK);
+        VisitChildren( pNode );
+    }
+
+    void Visit( SmErrorNode* pNode ) SAL_OVERRIDE {
+        CPPUNIT_ASSERT_EQUAL_MESSAGE("SmErrorNode should have type NERROR",
+                                     pNode->GetType(), NERROR);
+        VisitChildren( pNode );
+    }
+
+    void Visit( SmLineNode* pNode ) SAL_OVERRIDE {
+        CPPUNIT_ASSERT_EQUAL_MESSAGE("SmLineNode should have type NLINE",
+                                     pNode->GetType(), NLINE);
+        VisitChildren( pNode );
+    }
+
+    void Visit( SmExpressionNode* pNode ) SAL_OVERRIDE {
+        CPPUNIT_ASSERT_EQUAL_MESSAGE("SmExpressionNode should have type NEXPRESSION",
+                                     pNode->GetType(), NEXPRESSION);
+        VisitChildren( pNode );
+    }
+
+    void Visit( SmPolyLineNode* pNode ) SAL_OVERRIDE {
+        CPPUNIT_ASSERT_EQUAL_MESSAGE("SmPolyLineNode should have type NPOLYLINE",
+                                     pNode->GetType(), NPOLYLINE);
+        VisitChildren( pNode );
+    }
+
+    void Visit( SmRootNode* pNode ) SAL_OVERRIDE {
+        CPPUNIT_ASSERT_EQUAL_MESSAGE("SmRootNode should have type NROOT",
+                                     pNode->GetType(), NROOT);
+        VisitChildren( pNode );
+    }
+
+    void Visit( SmRootSymbolNode* pNode ) SAL_OVERRIDE {
+        CPPUNIT_ASSERT_EQUAL_MESSAGE("SmRootSymbolNode should have type NROOTSYMBOL",
+                                     pNode->GetType(), NROOTSYMBOL);
+        VisitChildren( pNode );
+    }
+
+    void Visit( SmDynIntegralNode* pNode ) SAL_OVERRIDE {
+        CPPUNIT_ASSERT_EQUAL_MESSAGE("SmDynIntegralNode should have type NDYNINT",
+                                     pNode->GetType(), NDYNINT);
+        VisitChildren( pNode );
+    }
+
+    void Visit( SmDynIntegralSymbolNode* pNode ) SAL_OVERRIDE {
+        CPPUNIT_ASSERT_EQUAL_MESSAGE("SmDynIntegralSymbolNode should have type NDYNINTSYMBOL",
+                                     pNode->GetType(), NDYNINTSYMBOL);
+        VisitChildren( pNode );
+    }
+
+    void Visit( SmRectangleNode* pNode ) SAL_OVERRIDE {
+        CPPUNIT_ASSERT_EQUAL_MESSAGE("SmRectangleNode should have type NRECTANGLE",
+                                     pNode->GetType(), NRECTANGLE);
+        VisitChildren( pNode );
+    }
+
+    void Visit( SmVerticalBraceNode* pNode ) SAL_OVERRIDE {
+        CPPUNIT_ASSERT_EQUAL_MESSAGE("SmVerticalBraceNode should have type NVERTICAL_BRACE",
+                                     pNode->GetType(), NVERTICAL_BRACE);
+        VisitChildren( pNode );
+    }
+
+private:
+    /** Auxiliary method for visiting the children of a pNode */
+    void VisitChildren( SmNode* pNode ) {
+        SmNodeIterator it( pNode );
+        while( it.Next() )
+            it->Accept( this );
+    }
+};
+
+#endif
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/starmath/qa/cppunit/test_nodetotextvisitors.cxx b/starmath/qa/cppunit/test_nodetotextvisitors.cxx
index b62212d..6b66d3a 100644
--- a/starmath/qa/cppunit/test_nodetotextvisitors.cxx
+++ b/starmath/qa/cppunit/test_nodetotextvisitors.cxx
@@ -18,6 +18,9 @@
 #include <visitors.hxx>
 #include <cursor.hxx>
 
+#include "mock-visitor.hxx"
+#include <boost/scoped_ptr.hpp>
+
 typedef tools::SvRef<SmDocShell> SmDocShellRef;
 
 using namespace ::com::sun::star;
@@ -443,6 +446,11 @@ void Test::parseandparseagain(const char *formula, const char *test_name)
         output1,
         output2);
 
+    // auxiliary test for Accept()
+    boost::scoped_ptr<MockVisitor> mv(new MockVisitor);
+    pNode1->Accept(mv.get());
+    pNode2->Accept(mv.get());
+
     delete pNode1;
     delete pNode2;
 }
@@ -464,6 +472,10 @@ void Test::ParseAndCheck(const char *formula, const char * expected, const char
         sExpected,
         sOutput);
 
+    // auxiliary test for Accept()
+    boost::scoped_ptr<MockVisitor> mv(new MockVisitor);
+    pNode->Accept(mv.get());
+
     delete pNode;
 }
 
@@ -487,6 +499,11 @@ void Test::ParseAndCompare(const char *formula1, const char *formula2, const cha
 
     CPPUNIT_ASSERT_EQUAL_MESSAGE(test_name, sOutput1, sOutput2);
 
+    // auxiliary test for Accept()
+    boost::scoped_ptr<MockVisitor> mv(new MockVisitor);
+    pNode1->Accept(mv.get());
+    pNode2->Accept(mv.get());
+
     delete pNode1;
     delete pNode2;
 }
diff --git a/starmath/source/visitors.cxx b/starmath/source/visitors.cxx
index 60f6127..5105079 100644
--- a/starmath/source/visitors.cxx
+++ b/starmath/source/visitors.cxx
@@ -13,189 +13,6 @@
 #include "tmpdevice.hxx"
 #include "cursor.hxx"
 
-// SmVisitorTest
-
-void SmVisitorTest::Visit( SmTableNode* pNode )
-{
-    assert( pNode->GetType( ) == NTABLE );
-    VisitChildren( pNode );
-}
-
-void SmVisitorTest::Visit( SmBraceNode* pNode )
-{
-    assert( pNode->GetType( ) == NBRACE );
-    VisitChildren( pNode );
-}
-
-void SmVisitorTest::Visit( SmBracebodyNode* pNode )
-{
-    assert( pNode->GetType( ) == NBRACEBODY );
-    VisitChildren( pNode );
-}
-
-void SmVisitorTest::Visit( SmOperNode* pNode )
-{
-    assert( pNode->GetType( ) == NOPER );
-    VisitChildren( pNode );
-}
-
-void SmVisitorTest::Visit( SmAlignNode* pNode )
-{
-    assert( pNode->GetType( ) == NALIGN );
-    VisitChildren( pNode );
-}
-
-void SmVisitorTest::Visit( SmAttributNode* pNode )
-{
-    assert( pNode->GetType( ) == NATTRIBUT );
-    VisitChildren( pNode );
-}
-
-void SmVisitorTest::Visit( SmFontNode* pNode )
-{
-    assert( pNode->GetType( ) == NFONT );
-    VisitChildren( pNode );
-}
-
-void SmVisitorTest::Visit( SmUnHorNode* pNode )
-{
-    assert( pNode->GetType( ) == NUNHOR );
-    VisitChildren( pNode );
-}
-
-void SmVisitorTest::Visit( SmBinHorNode* pNode )
-{
-    assert( pNode->GetType( ) == NBINHOR );
-    VisitChildren( pNode );
-}
-
-void SmVisitorTest::Visit( SmBinVerNode* pNode )
-{
-    assert( pNode->GetType( ) == NBINVER );
-    VisitChildren( pNode );
-}
-
-void SmVisitorTest::Visit( SmBinDiagonalNode* pNode )
-{
-    assert( pNode->GetType( ) == NBINDIAGONAL );
-    VisitChildren( pNode );
-}
-
-void SmVisitorTest::Visit( SmSubSupNode* pNode )
-{
-    assert( pNode->GetType( ) == NSUBSUP );
-    VisitChildren( pNode );
-}
-
-void SmVisitorTest::Visit( SmMatrixNode* pNode )
-{
-    assert( pNode->GetType( ) == NMATRIX );
-    VisitChildren( pNode );
-}
-
-void SmVisitorTest::Visit( SmPlaceNode* pNode )
-{
-    assert( pNode->GetType( ) == NPLACE );
-    VisitChildren( pNode );
-}
-
-void SmVisitorTest::Visit( SmTextNode* pNode )
-{
-    assert( pNode->GetType( ) == NTEXT );
-    VisitChildren( pNode );
-}
-
-void SmVisitorTest::Visit( SmSpecialNode* pNode )
-{
-    assert( pNode->GetType( ) == NSPECIAL );
-    VisitChildren( pNode );
-}
-
-void SmVisitorTest::Visit( SmGlyphSpecialNode* pNode )
-{
-    assert( pNode->GetType( ) == NGLYPH_SPECIAL );
-    VisitChildren( pNode );
-}
-
-void SmVisitorTest::Visit( SmMathSymbolNode* pNode )
-{
-    assert( pNode->GetType( ) == NMATH || pNode->GetType( ) == NMATHIDENT );
-    VisitChildren( pNode );
-}
-
-void SmVisitorTest::Visit( SmBlankNode* pNode )
-{
-    assert( pNode->GetType( ) == NBLANK );
-    VisitChildren( pNode );
-}
-
-void SmVisitorTest::Visit( SmErrorNode* pNode )
-{
-    assert( pNode->GetType( ) == NERROR );
-    VisitChildren( pNode );
-}
-
-void SmVisitorTest::Visit( SmLineNode* pNode )
-{
-    assert( pNode->GetType( ) == NLINE );
-    VisitChildren( pNode );
-}
-
-void SmVisitorTest::Visit( SmExpressionNode* pNode )
-{
-    assert( pNode->GetType( ) == NEXPRESSION );
-    VisitChildren( pNode );
-}
-
-void SmVisitorTest::Visit( SmPolyLineNode* pNode )
-{
-    assert( pNode->GetType( ) == NPOLYLINE );
-    VisitChildren( pNode );
-}
-
-void SmVisitorTest::Visit( SmRootNode* pNode )
-{
-    assert( pNode->GetType( ) == NROOT );
-    VisitChildren( pNode );
-}
-
-void SmVisitorTest::Visit( SmRootSymbolNode* pNode )
-{
-    assert( pNode->GetType( ) == NROOTSYMBOL );
-    VisitChildren( pNode );
-}
-
-void SmVisitorTest::Visit( SmDynIntegralNode* pNode )
-{
-    assert( pNode->GetType( ) == NDYNINT );
-    VisitChildren( pNode );
-}
-
-void SmVisitorTest::Visit( SmDynIntegralSymbolNode* pNode )
-{
-    assert( pNode->GetType( ) == NDYNINTSYMBOL );
-    VisitChildren( pNode );
-}
-
-void SmVisitorTest::Visit( SmRectangleNode* pNode )
-{
-    assert( pNode->GetType( ) == NRECTANGLE );
-    VisitChildren( pNode );
-}
-
-void SmVisitorTest::Visit( SmVerticalBraceNode* pNode )
-{
-    assert( pNode->GetType( ) == NVERTICAL_BRACE );
-    VisitChildren( pNode );
-}
-
-void SmVisitorTest::VisitChildren( SmNode* pNode )
-{
-    SmNodeIterator it( pNode );
-    while( it.Next( ) )
-        it->Accept( this );
-}
-
 // SmDefaultingVisitor
 
 void SmDefaultingVisitor::Visit( SmTableNode* pNode )


More information about the Libreoffice-commits mailing list