[PATCH] Put brackets around binoms in SmNodeToTextVisitor, with test

Luke Dixon 6b8b4567 at gmail.com
Sun Dec 19 07:24:46 PST 2010


---
 starmath/qa/cppunit/test_nodetotextvisitors.cxx |   37 +++++++++++++++++++++++
 starmath/source/visitors.cxx                    |    3 +-
 2 files changed, 39 insertions(+), 1 deletions(-)

diff --git a/starmath/qa/cppunit/test_nodetotextvisitors.cxx b/starmath/qa/cppunit/test_nodetotextvisitors.cxx
index 45386d1..e5b9e93 100644
--- a/starmath/qa/cppunit/test_nodetotextvisitors.cxx
+++ b/starmath/qa/cppunit/test_nodetotextvisitors.cxx
@@ -41,6 +41,7 @@
 #include <document.hxx>
 #include <node.hxx>
 #include <visitors.hxx>
+#include <cursor.hxx>
 
 #include "preextstl.h"
 #include <cppunit/TestSuite.h>
@@ -72,6 +73,14 @@ struct assertion_traits<String>
 SO2_DECL_REF(SmDocShell)
 SO2_IMPL_REF(SmDocShell)
 
+class TestOutputDevice : public OutputDevice
+{
+public:
+    TestOutputDevice()
+    {
+    }
+};
+
 using namespace ::com::sun::star;
 
 namespace {
@@ -95,6 +104,7 @@ public:
     void SimpleFormats();
     void SimpleGreekChars();
     void SimpleSpecialChars();
+    void testBinomInBinHor();
 
     CPPUNIT_TEST_SUITE(Test);
     CPPUNIT_TEST(SimpleUnaryOp);
@@ -109,6 +119,7 @@ public:
     CPPUNIT_TEST(SimpleFormats);
     CPPUNIT_TEST(SimpleGreekChars);
     CPPUNIT_TEST(SimpleSpecialChars);
+    CPPUNIT_TEST(testBinomInBinHor);
     CPPUNIT_TEST_SUITE_END();
 
 private:
@@ -480,6 +491,32 @@ void Test::parseandparseagain(const char *formula, const char *test_name)
     delete pNode2;
 }
 
+void Test::testBinomInBinHor()
+{
+    String sInput, sExpected, sOutput;
+    SmNode* pTree;
+
+    // set up a binom (table) node
+    sInput.AppendAscii("binom a b + c");
+    pTree = SmParser().Parse(sInput);
+    pTree->Prepare(xDocShRef->GetFormat(), *xDocShRef);
+
+    SmCursor aCursor(pTree, xDocShRef);
+    TestOutputDevice aOutputDevice;
+
+    // move forward (more than) enough places to be at the end
+    int i;
+    for (i = 0; i < 8; ++i)
+        aCursor.Move(&aOutputDevice, MoveRight);
+
+    // tack +d on the end, which will put the binom into an SmBinHorNode
+    aCursor.InsertElement(PlusElement);
+    aCursor.InsertText('d');
+
+    sExpected.AppendAscii(" { { binom a b + c } + d } ");
+    CPPUNIT_ASSERT_EQUAL_MESSAGE("Binom Node in BinHor Node", sExpected, xDocShRef->GetText());
+}
+
 CPPUNIT_TEST_SUITE_REGISTRATION(Test);
 
 }
diff --git a/starmath/source/visitors.cxx b/starmath/source/visitors.cxx
index 2e7e4e3..fbdb379 100644
--- a/starmath/source/visitors.cxx
+++ b/starmath/source/visitors.cxx
@@ -2163,9 +2163,10 @@ void SmSelectionDrawingVisitor::Visit( SmTextNode* pNode )
 void SmNodeToTextVisitor::Visit( SmTableNode* pNode )
 {
     if( pNode->GetToken( ).eType == TBINOM ) {
-        Append( "binom" );
+        Append( "{ binom" );
         LineToText( pNode->GetSubNode( 0 ) );
         LineToText( pNode->GetSubNode( 1 ) );
+        Append("} ");
     } else if( pNode->GetToken( ).eType == TSTACK ) {
         Append( "stack{ " );
         SmNodeIterator it( pNode );
-- 
1.7.3.3


--=-Y5EVmkHJREfGEHtV81Vz--



More information about the LibreOffice mailing list