LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/starmath/qa/cppunit - test_nodetotextvisitors.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 426 430 99.1 %
Date: 2013-07-09 Functions: 40 42 95.2 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       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             :  */
       9             : 
      10             : #include <sal/config.h>
      11             : #include <test/bootstrapfixture.hxx>
      12             : 
      13             : #include <vcl/svapp.hxx>
      14             : #include <smdll.hxx>
      15             : 
      16             : #include <document.hxx>
      17             : #include <node.hxx>
      18             : #include <visitors.hxx>
      19             : #include <cursor.hxx>
      20             : 
      21             : namespace CppUnit {
      22             : template<>
      23             : struct assertion_traits<String>
      24             : {
      25           3 :     static bool equal(const String& x, const String& y)
      26             :     {
      27           3 :         return x == y;
      28             :     }
      29             : 
      30           0 :     static std::string toString(const String& x)
      31             :     {
      32           0 :         OStringStream ost;
      33           0 :         ost << OUStringToOString(x, RTL_TEXTENCODING_UTF8).getStr();
      34           0 :         return ost.str();
      35             :     }
      36             : };
      37             : }
      38             : 
      39        1127 : SV_DECL_REF(SmDocShell)
      40         120 : SV_IMPL_REF(SmDocShell)
      41             : 
      42           4 : class TestOutputDevice : public OutputDevice
      43             : {
      44             : public:
      45           4 :     TestOutputDevice()
      46           4 :     {
      47           4 :     }
      48             : };
      49             : 
      50             : using namespace ::com::sun::star;
      51             : 
      52             : namespace {
      53             : 
      54          48 : class Test : public test::BootstrapFixture {
      55             : 
      56             : public:
      57             :     // init
      58             :     virtual void setUp();
      59             :     virtual void tearDown();
      60             : 
      61             :     // tests
      62             :     void SimpleUnaryOp();
      63             :     void SimpleBinaryOp();
      64             :     void SimpleRelationalOp();
      65             :     void SimpleSetOp();
      66             :     void SimpleFunctions();
      67             :     void SimpleOperators();
      68             :     void SimpleAttributes();
      69             :     void SimpleMisc();
      70             :     void SimpleBrackets();
      71             :     void SimpleFormats();
      72             :     void SimpleGreekChars();
      73             :     void SimpleSpecialChars();
      74             :     void testBinomInBinHor();
      75             :     void testBinVerInUnary();
      76             :     void testBinHorInSubSup();
      77             :     void testUnaryInMixedNumberAsNumerator();
      78             : 
      79           2 :     CPPUNIT_TEST_SUITE(Test);
      80           1 :     CPPUNIT_TEST(SimpleUnaryOp);
      81           1 :     CPPUNIT_TEST(SimpleBinaryOp);
      82           1 :     CPPUNIT_TEST(SimpleRelationalOp);
      83           1 :     CPPUNIT_TEST(SimpleSetOp);
      84           1 :     CPPUNIT_TEST(SimpleFunctions);
      85           1 :     CPPUNIT_TEST(SimpleOperators);
      86           1 :     CPPUNIT_TEST(SimpleAttributes);
      87           1 :     CPPUNIT_TEST(SimpleMisc);
      88           1 :     CPPUNIT_TEST(SimpleBrackets);
      89           1 :     CPPUNIT_TEST(SimpleFormats);
      90           1 :     CPPUNIT_TEST(SimpleGreekChars);
      91           1 :     CPPUNIT_TEST(SimpleSpecialChars);
      92           1 :     CPPUNIT_TEST(testBinomInBinHor);
      93           1 :     CPPUNIT_TEST(testBinVerInUnary);
      94           1 :     CPPUNIT_TEST(testBinHorInSubSup);
      95           1 :     CPPUNIT_TEST(testUnaryInMixedNumberAsNumerator);
      96           2 :     CPPUNIT_TEST_SUITE_END();
      97             : 
      98             : private:
      99             :     uno::Reference< uno::XComponentContext > m_context;
     100             :     SmDocShellRef xDocShRef;
     101             :     void parseandparseagain(const char *input, const char *test_name);
     102             :     void ParseAndCheck(const char *input, const char *expected, const char *test_name);
     103             : };
     104             : 
     105          16 : void Test::setUp()
     106             : {
     107          16 :     BootstrapFixture::setUp();
     108             : 
     109          16 :     SmGlobals::ensure();
     110             : 
     111          16 :     xDocShRef = new SmDocShell(SFXOBJECTSHELL_STD_NORMAL);
     112          16 : }
     113             : 
     114          16 : void Test::tearDown()
     115             : {
     116          16 :     xDocShRef.Clear();
     117          16 :     BootstrapFixture::tearDown();
     118          16 : }
     119             : 
     120             : /*
     121             :  * Most of the formula commands in this file came from:
     122             :  * http://wiki.services.openoffice.org/wiki/Template:Math_commands_reference
     123             :  * which was licensed with a
     124             :  * Creative Common Attribution 3.0 license and written by:
     125             :  * Jeanweber, Weegreenblobbie, Jdpipe, TJFrazier, Ysangkok, B michaelsen, Spellbreaker
     126             :  */
     127             : 
     128           1 : void Test::SimpleUnaryOp()
     129             : {
     130           1 :     parseandparseagain("+1", "Positive (plus)");
     131           1 :     parseandparseagain("-2", "Negative (minus)");
     132           1 :     parseandparseagain("+-3", "Plus/minus");
     133           1 :     parseandparseagain("-+4", "Minus/plus");
     134           1 :     parseandparseagain("neg a", "Boolean 'not'");
     135           1 :     parseandparseagain("fact a", "Factorial");
     136           1 :     parseandparseagain(" - { 1 over 2 } ", "BinVer in Unary 1");
     137           1 :     ParseAndCheck(" - { 1 over 2 } ", " - { 1 over 2 } ", "BinVer in Unary 1");
     138           1 :     parseandparseagain(" { - { 1 over 2 } } ", "BinVer in Unary 2");
     139           1 :     parseandparseagain(" - 1 over 2 ", "Unary in BinVer as numerator 1");
     140           1 :     parseandparseagain(" { - 1 } over 2 ", "Unary in BinVer as numerator 2");
     141           1 :     parseandparseagain(" 1 over - 2 ", "Unary in BinVer as denominator 1");
     142           1 :     parseandparseagain(" 1 over { - 2 } ", "Unary in BinVer as denominator 2");
     143           1 :     parseandparseagain(" 2 { - 1 over 2 } ", "Mixed number with Unary in denominator 1");
     144           1 :     parseandparseagain(" 2 { - 1 } over 2 ", "Mixed number with Unary in denominator 2");
     145           1 :     parseandparseagain(" - 1 + 2 ", "Unary in BinHor");
     146           1 : }
     147             : 
     148           1 : void Test::SimpleBinaryOp()
     149             : {
     150           1 :     parseandparseagain("a + b", "Addition");
     151           1 :     parseandparseagain("a cdot b", "Dot product");
     152           1 :     parseandparseagain("a times b", "Cross product");
     153           1 :     parseandparseagain("a * b", "Multiplication (asterisk)");
     154           1 :     parseandparseagain("a and b", "Boolean 'and'");
     155           1 :     parseandparseagain("a - b", "Subtraction");
     156           1 :     parseandparseagain("a over b", "Division (as a fraction)");
     157           1 :     parseandparseagain("a div b", "Division (as an operator)");
     158           1 :     parseandparseagain("a / b", "Division (with a slash)");
     159           1 :     parseandparseagain("a or b", "Boolean 'or'");
     160           1 :     parseandparseagain("a circ b", "Concatenation");
     161           1 : }
     162             : 
     163           1 : void Test::SimpleRelationalOp()
     164             : {
     165           1 :     parseandparseagain("a = b", "Is equal");
     166           1 :     parseandparseagain("a <> b", "Is not equal");
     167           1 :     parseandparseagain("a approx 2", "Approximately");
     168           1 :     parseandparseagain("a divides b", "Divides");
     169           1 :     parseandparseagain("a ndivides b", "Does not divide");
     170           1 :     parseandparseagain("a < 2", "Less than");
     171           1 :     parseandparseagain("a > 2", "Greater than");
     172           1 :     parseandparseagain("a simeq b", "Similar to or equal");
     173           1 :     parseandparseagain("a parallel b", "Parallel");
     174           1 :     parseandparseagain("a ortho b", "Orthogonal to");
     175           1 :     parseandparseagain("a leslant b", "Less than or equal to");
     176           1 :     parseandparseagain("a geslant b", "Greater than or equal to");
     177           1 :     parseandparseagain("a sim b", "Similar to");
     178           1 :     parseandparseagain("a equiv b", "Congruent");
     179           1 :     parseandparseagain("a <= b", "Less than or equal to");
     180           1 :     parseandparseagain("a >= b", "Greater than or equal to");
     181           1 :     parseandparseagain("a prop b", "Proportional");
     182           1 :     parseandparseagain("a toward b", "Toward");
     183           1 :     parseandparseagain("a dlarrow b", "Arrow left");
     184           1 :     parseandparseagain("a dlrarrow b", "Double arrow left and right");
     185           1 :     parseandparseagain("drarrow b", "Arrow right");
     186           1 : }
     187             : 
     188           1 : void Test::SimpleSetOp()
     189             : {
     190           1 :     parseandparseagain("a in B", "Is in");
     191           1 :     parseandparseagain("a notin B", "Is not in");
     192           1 :     parseandparseagain("A owns b", "Owns");
     193           1 :     parseandparseagain("emptyset", "Empty set");
     194           1 :     parseandparseagain("A intersection B", "Intersection");
     195           1 :     parseandparseagain("A union B", "Union");
     196           1 :     parseandparseagain("A setminus B", "Difference");
     197           1 :     parseandparseagain("A slash B", "Quotient");
     198           1 :     parseandparseagain("aleph", "Aleph");
     199           1 :     parseandparseagain("A subset B", "Subset");
     200           1 :     parseandparseagain("A subseteq B", "Subset or equal to");
     201           1 :     parseandparseagain("A supset B", "Superset");
     202           1 :     parseandparseagain("A supseteq B", "Superset or equal to");
     203           1 :     parseandparseagain("A nsubset B", "Not subset");
     204           1 :     parseandparseagain("A nsubseteq B", "Not subset or equal");
     205           1 :     parseandparseagain("A nsupset B", "Not superset");
     206           1 :     parseandparseagain("A nsupseteq B", "Not superset or equal");
     207           1 :     parseandparseagain("setN", "Set of natural numbers");
     208           1 :     parseandparseagain("setZ", "Set of integers");
     209           1 :     parseandparseagain("setQ", "Set of rational numbers");
     210           1 :     parseandparseagain("setR", "Set of real numbers");
     211           1 :     parseandparseagain("setC", "Set of complex numbers");
     212           1 : }
     213             : 
     214           1 : void Test::SimpleFunctions()
     215             : {
     216           1 :     parseandparseagain("func e^{a}", "Exponential");
     217           1 :     parseandparseagain("ln(a)", "Natural logarithm");
     218           1 :     parseandparseagain("exp(a)", "Exponential function");
     219           1 :     parseandparseagain("log(a)", "Logarithm");
     220           1 :     parseandparseagain("a^{b}", "Power");
     221           1 :     parseandparseagain("sin(a)", "Sine");
     222           1 :     parseandparseagain("cos(a)", "Cosine");
     223           1 :     parseandparseagain("tan(a)", "Tangent");
     224           1 :     parseandparseagain("cot(a)", "Cotangent");
     225           1 :     parseandparseagain("sqrt{a}", "Square root");
     226           1 :     parseandparseagain("arcsin(a)", "Arcsine");
     227           1 :     parseandparseagain("arccos(a)", "Arccosine");
     228           1 :     parseandparseagain("arctan(a)", "Arctangent");
     229           1 :     parseandparseagain("arccot(a)", "Arc cotangent");
     230           1 :     parseandparseagain("nroot{a}{b}", "nth root");
     231           1 :     parseandparseagain("sinh(a)", "Hyperbolic sine");
     232           1 :     parseandparseagain("cosh(a)", "Hyperbolic cosine");
     233           1 :     parseandparseagain("tanh(a)", "Hyperbolic tangent");
     234           1 :     parseandparseagain("coth(a)", "Hyperbolic cotangent");
     235           1 :     parseandparseagain("abs{a}", "Absolute value");
     236           1 :     parseandparseagain("arsinh(a)", "Arc hyperbolic sine");
     237           1 :     parseandparseagain("arcosh(a)", "Arc hyperbolic cosine");
     238           1 :     parseandparseagain("artanh(a)", "Arc hyperbolic tangent");
     239           1 :     parseandparseagain("arcoth(a)", "Arc hyperbolic cotangent");
     240           1 : }
     241             : 
     242           1 : void Test::SimpleOperators()
     243             : {
     244           1 :     parseandparseagain("lim{a}", "Limit");
     245           1 :     parseandparseagain("sum{a}", "Sum");
     246           1 :     parseandparseagain("prod{a}", "Product");
     247           1 :     parseandparseagain("coprod{a}", "Coproduct");
     248             : //FIXME    parseandparseagain("int from {r_0} to {r_t} a", "Upper and lower bounds shown with integral (from & to)");
     249             : //FIXME    ParseAndCheck("int csup {r_0} csub {r_t} a", "int csup { r rsub 0 } csub { r rsub t } a ", "Upper and lower bounds shown with integral (csub & csup)");
     250             : //FIXME    ParseAndCheck("sum csup { size 8 { x - 1 } } csub { size 8 a } b ", "sum csup { size 8 { x - 1 } } csub { size 8 a } b ", "Sum with sized upper and lower bounds");
     251           1 :     parseandparseagain("int{a}", "Integral");
     252           1 :     parseandparseagain("iint{a}", "Double integral");
     253           1 :     parseandparseagain("iiint{a}", "Triple integral");
     254           1 :     parseandparseagain("sum from{3}b", "Lower bound shown with summation symbol");
     255           1 :     parseandparseagain("lint a", "Contour integral");
     256           1 :     parseandparseagain("llint a", "Double curved integral");
     257           1 :     parseandparseagain("lllint a", "Triple curved integral");
     258           1 :     parseandparseagain("prod from {i=1} to {n} {(i+1)}", "Product with range");
     259           1 : }
     260             : 
     261           1 : void Test::SimpleAttributes()
     262             : {
     263           1 :     parseandparseagain("acute a", "Acute accent");
     264           1 :     parseandparseagain("grave a", "Grave accent");
     265           1 :     parseandparseagain("check a", "Reverse circumflex");
     266           1 :     parseandparseagain("breve a", "Breve");
     267           1 :     parseandparseagain("circle a", "Circle");
     268           1 :     parseandparseagain("vec a", "Vector arrow");
     269           1 :     parseandparseagain("tilde a", "Tilde");
     270           1 :     parseandparseagain("hat a", "Circumflex");
     271           1 :     parseandparseagain("bar a", "Line above");
     272           1 :     parseandparseagain("dot a", "Dot");
     273           1 :     parseandparseagain("widevec abc", "Wide vector arrow");
     274           1 :     parseandparseagain("widetilde abc", "Wide tilde");
     275           1 :     parseandparseagain("widehat abc", "Wide circumflex");
     276           1 :     parseandparseagain("ddot a", "Double dot");
     277           1 :     parseandparseagain("overline abc", "Line over");
     278           1 :     parseandparseagain("underline abc", "Line under");
     279           1 :     parseandparseagain("overstrike abc", "Line through");
     280           1 :     parseandparseagain("dddot a", "Triple dot");
     281           1 :     parseandparseagain("phantom a", "Transparent (useful to get a placeholder of a given size)");
     282           1 :     parseandparseagain("bold a", "Bold font");
     283           1 :     parseandparseagain("ital a", "Italic font");
     284           1 :     parseandparseagain("nitalic a", "Roman (non-italic) font 1");
     285           1 :     parseandparseagain("\"a\"", "Roman (non-italic) font 2");
     286           1 :     parseandparseagain("size 16 qv", "Resize font");
     287           1 :     parseandparseagain("font sans qv", "Sans serif font");
     288           1 :     parseandparseagain("font serif qv", "Serif font");
     289           1 :     parseandparseagain("font fixed qv", "Fixed font");
     290           1 :     parseandparseagain("color cyan qv", "Cyan color");
     291           1 :     parseandparseagain("color yellow qv", "Yellow color");
     292           1 :     parseandparseagain("color white qv", "White color");
     293           1 :     parseandparseagain("color green qv", "Green color");
     294           1 :     parseandparseagain("color blue qv", "Blue color");
     295           1 :     parseandparseagain("color red qv", "Red color");
     296           1 :     parseandparseagain("color green X qv", "Green color changes back");
     297           1 :     parseandparseagain("color green {X qv}", "Green color, more than one item");
     298           1 : }
     299             : 
     300           1 : void Test::SimpleMisc()
     301             : {
     302           1 :     parseandparseagain("infinity", "Infinity");
     303           1 :     parseandparseagain("partial", "Partial");
     304           1 :     parseandparseagain("nabla", "Nabla");
     305           1 :     parseandparseagain("exists", "There exists");
     306           1 :     parseandparseagain("notexists", "There not exists");
     307           1 :     parseandparseagain("forall", "For all");
     308           1 :     parseandparseagain("hbar", "H bar");
     309           1 :     parseandparseagain("lambdabar", "Lambda bar");
     310           1 :     parseandparseagain("re", "Real part");
     311           1 :     parseandparseagain("im", "Imaginary part");
     312           1 :     parseandparseagain("wp", "Weierstrass p");
     313           1 :     parseandparseagain("leftarrow", "Left arrow");
     314           1 :     parseandparseagain("rightarrow", "Right arrow");
     315           1 :     parseandparseagain("uparrow", "Up arrow");
     316           1 :     parseandparseagain("downarrow", "Down arrow");
     317           1 :     parseandparseagain("dotslow", "Dots at bottom");
     318           1 :     parseandparseagain("dotsaxis", "Dots at middle");
     319           1 :     parseandparseagain("dotsvert", "Dots vertical");
     320           1 :     parseandparseagain("dotsup", "Dots diagonal upward");
     321           1 :     parseandparseagain("dotsdown", "Dots diagonal downward");
     322           1 : }
     323             : 
     324           1 : void Test::SimpleBrackets()
     325             : {
     326           1 :     parseandparseagain("(a)", "Round Brackets");
     327           1 :     parseandparseagain("[b]", "Square Brackets");
     328           1 :     parseandparseagain("ldbracket c rdbracket", "Double Square Brackets");
     329           1 :     parseandparseagain("lline a rline", "Single line or absolute");
     330           1 :     parseandparseagain("abs a", "Single line or absolute 2");
     331           1 :     parseandparseagain("ldline a rdline", "Double line");
     332           1 :     parseandparseagain("lbrace w rbrace", "Braces");
     333           1 :     parseandparseagain("left lbrace stack{0, n <> 0 # 1, n = 1} right none", "Single left brace");
     334           1 :     parseandparseagain("langle d rangle", "Angle Brackets");
     335           1 :     parseandparseagain("langle a mline b rangle", "Operator Brackets");
     336           1 :     parseandparseagain("{a}", "Group brackets (used for program control)");
     337           1 :     parseandparseagain("left ( stack{a # b # z} right )", "Round brackets scalable");
     338           1 :     parseandparseagain("left [ stack{x # y} right ]", "Square brackets scalable");
     339           1 :     parseandparseagain("left ldbracket c right rdbracket", "Double square brackets scalable");
     340           1 :     parseandparseagain("left lline a right rline", "Line scalable");
     341           1 :     parseandparseagain("left ldline d right rdline", "Double line scalable");
     342           1 :     parseandparseagain("left lbrace e right rbrace", "Brace scalable");
     343           1 :     parseandparseagain("left langle f right rangle", "Angle bracket scalable");
     344           1 :     parseandparseagain("left langle g mline h right rangle", "Operator brackets scalable");
     345           1 :     parseandparseagain("{a} overbrace b", "Over brace scalable");
     346           1 :     parseandparseagain("{b} underbrace a", "Under brace scalable");
     347           1 : }
     348             : 
     349           1 : void Test::SimpleFormats()
     350             : {
     351           1 :     parseandparseagain("a lsup{b}", "Left superscript");
     352           1 :     parseandparseagain("a csup{b}", "Center superscript");
     353           1 :     parseandparseagain("a^{b}", "Right superscript");
     354           1 :     parseandparseagain("a lsub{b}", "Left subscript");
     355           1 :     parseandparseagain("a csub{b}", "Center subscript");
     356           1 :     parseandparseagain("a_{b}", "Right subscript");
     357           1 :     parseandparseagain("stack { Hello world # alignl (a) }", "Align character to left");
     358           1 :     parseandparseagain("stack{Hello world # alignc(a)}", "Align character to center");
     359           1 :     parseandparseagain("stack { Hello world # alignr(a)}", "Align character to right");
     360           1 :     parseandparseagain("binom{a}{b}", "Vertical stack of 2");
     361           1 :     parseandparseagain("stack{a # b # z}", "Vertical stack, more than 2");
     362           1 :     parseandparseagain("matrix{a # b ## c # d}", "Matrix");
     363           1 :     parseandparseagain("matrix{a # \"=\" # alignl{b} ## {} # \"=\" # alignl{c+1}}", "Equations aligned at '=' (using 'matrix') ");
     364           1 :     parseandparseagain("stack{alignl{a} = b # alignl{phantom{a} = c+1}}", "Equations aligned at '=' (using 'phantom') ");
     365           1 :     parseandparseagain("asldkfjo newline sadkfj", "New line");
     366           1 :     parseandparseagain("stuff `stuff", "Small gap (grave)");
     367           1 :     parseandparseagain("stuff~stuff", "Large gap (tilde)");
     368           1 : }
     369             : 
     370           1 : void Test::SimpleGreekChars()
     371             : {
     372           1 :     parseandparseagain("%ALPHA", "Capital alpha");
     373           1 :     parseandparseagain("%BETA", "Capital beta");
     374           1 :     parseandparseagain("%CHI", "Capital chi");
     375           1 :     parseandparseagain("%DELTA", "Capital delta");
     376           1 :     parseandparseagain("%EPSILON", "Capital epsilon");
     377           1 :     parseandparseagain("%ETA", "Capital eta");
     378           1 :     parseandparseagain("%GAMMA", "Capital gamma");
     379           1 :     parseandparseagain("%IOTA", "Capital iota");
     380           1 :     parseandparseagain("%LAMBDA", "Capital lambda");
     381           1 :     parseandparseagain("%MU", "Capital mu");
     382           1 :     parseandparseagain("%NU", "Capital nu");
     383           1 :     parseandparseagain("%OMEGA", "Capital omega");
     384           1 :     parseandparseagain("%OMICRON", "Capital omicron");
     385           1 :     parseandparseagain("%PHI", "Capital phi");
     386           1 :     parseandparseagain("%PI", "Capital pi");
     387           1 :     parseandparseagain("%PSI", "Capital psi");
     388           1 :     parseandparseagain("%RHO", "Capital rho");
     389           1 :     parseandparseagain("%SIGMA", "Capital sigma");
     390           1 :     parseandparseagain("%TAU", "Capital tau");
     391           1 :     parseandparseagain("%THETA", "Capital theta");
     392           1 :     parseandparseagain("%UPSILON", "Capital upsilon");
     393           1 :     parseandparseagain("%XI", "Capital xi");
     394           1 :     parseandparseagain("%ZETA", "Capital zeta");
     395           1 :     parseandparseagain("%alpha", "lowercase alpha");
     396           1 :     parseandparseagain("%beta", "lowercase beta");
     397           1 :     parseandparseagain("%chi", "lowercase chi");
     398           1 :     parseandparseagain("%delta", "lowercase delta");
     399           1 :     parseandparseagain("%epsilon", "lowercase epsilon");
     400           1 :     parseandparseagain("%eta", "lowercase eta");
     401           1 :     parseandparseagain("%gamma", "lowercase gamma");
     402           1 :     parseandparseagain("%iota", "lowercase iota");
     403           1 :     parseandparseagain("%kappa", "lowercase kappa");
     404           1 :     parseandparseagain("%lambda", "lowercase lambda");
     405           1 :     parseandparseagain("%mu", "lowercase mu");
     406           1 :     parseandparseagain("%nu", "lowercase nu");
     407           1 :     parseandparseagain("%omega", "lowercase omega");
     408           1 :     parseandparseagain("%omicron", "lowercase omicron");
     409           1 :     parseandparseagain("%phi", "lowercase phi");
     410           1 :     parseandparseagain("%pi", "lowercase pi");
     411           1 :     parseandparseagain("%psi", "lowercase psi");
     412           1 :     parseandparseagain("%rho", "lowercase rho");
     413           1 :     parseandparseagain("%sigma", "lowercase sigma");
     414           1 :     parseandparseagain("%tau", "lowercase tau");
     415           1 :     parseandparseagain("%theta", "lowercase theta");
     416           1 :     parseandparseagain("%upsilon", "lowercase upsilon");
     417           1 :     parseandparseagain("%varepsilon", "Varepsilon");
     418           1 :     parseandparseagain("%varphi", "Varphi");
     419           1 :     parseandparseagain("%varpi", "Varpi");
     420           1 :     parseandparseagain("%varrho", "Varrho");
     421           1 :     parseandparseagain("%varsigma", "Varsigma");
     422           1 :     parseandparseagain("%vartheta", "Vartheta");
     423           1 :     parseandparseagain("%xi", "lowercase xi");
     424           1 :     parseandparseagain("%zeta", "lowercase zeta");
     425           1 : }
     426             : 
     427           1 : void Test::SimpleSpecialChars()
     428             : {
     429           1 :     parseandparseagain("%and", "And");
     430           1 :     parseandparseagain("%angle", "Angle");
     431           1 :     parseandparseagain("%element", "Element");
     432           1 :     parseandparseagain("%identical", "Identical");
     433           1 :     parseandparseagain("%infinite", "Infinite");
     434           1 :     parseandparseagain("%noelement", "No element");
     435           1 :     parseandparseagain("%notequal", "Not equal");
     436           1 :     parseandparseagain("%or", "Or");
     437           1 :     parseandparseagain("%perthousand", "Per thousand");
     438           1 :     parseandparseagain("%strictlygreaterthan", "Strictly greater than");
     439           1 :     parseandparseagain("%strictlylessthan", "Strictly less than");
     440           1 :     parseandparseagain("%tendto", "Tend to");
     441           1 : }
     442             : 
     443             : /* This test takes a formula command, parses it, converts the node to text,
     444             :  * parses it again, converts it to text again, and compares the values.
     445             :  * Doing this doesn't prove that it is correct, but it should prove that the
     446             :  * meaning of the original command is not being changed.
     447             :  */
     448         263 : void Test::parseandparseagain(const char *formula, const char *test_name)
     449             : {
     450         526 :     OUString output1, output2;
     451             :     SmNode *pNode1, *pNode2;
     452             : 
     453             :     // parse 1
     454         526 :     OUString input = OUString::createFromAscii(formula);
     455         263 :     pNode1 = SmParser().ParseExpression(input);
     456         263 :     pNode1->Prepare(xDocShRef->GetFormat(), *xDocShRef);
     457         263 :     SmNodeToTextVisitor(pNode1, output1);
     458             : 
     459             :     // parse 2
     460         263 :     pNode2 = SmParser().ParseExpression(output1);
     461         263 :     pNode2->Prepare(xDocShRef->GetFormat(), *xDocShRef);
     462         263 :     SmNodeToTextVisitor(pNode2, output2);
     463             : 
     464             :     // compare
     465         526 :     CPPUNIT_ASSERT_EQUAL_MESSAGE(test_name,
     466             :         output1,
     467         263 :         output2);
     468             : 
     469         263 :     delete pNode1;
     470         526 :     delete pNode2;
     471         263 : }
     472             : 
     473           1 : void Test::ParseAndCheck(const char *formula, const char * expected, const char *test_name)
     474             : {
     475           1 :     OUString sOutput;
     476             :     SmNode *pNode;
     477             : 
     478             :     // parse
     479           2 :     OUString sInput = OUString::createFromAscii(formula);
     480           1 :     pNode = SmParser().ParseExpression(sInput);
     481           1 :     pNode->Prepare(xDocShRef->GetFormat(), *xDocShRef);
     482           1 :     SmNodeToTextVisitor(pNode, sOutput);
     483             : 
     484             :     // compare
     485           2 :     OUString sExpected = OUString::createFromAscii(expected);
     486           2 :     CPPUNIT_ASSERT_EQUAL_MESSAGE(test_name,
     487             :         sExpected,
     488           1 :         sOutput);
     489             : 
     490           2 :     delete pNode;
     491           1 : }
     492             : 
     493           1 : void Test::testBinomInBinHor()
     494             : {
     495           2 :     String sInput, sExpected;
     496             :     SmNode* pTree;
     497             : 
     498             :     // set up a binom (table) node
     499           1 :     sInput.AppendAscii("binom a b + c");
     500           1 :     pTree = SmParser().Parse(sInput);
     501           1 :     pTree->Prepare(xDocShRef->GetFormat(), *xDocShRef);
     502             : 
     503           2 :     SmCursor aCursor(pTree, xDocShRef);
     504           2 :     TestOutputDevice aOutputDevice;
     505             : 
     506             :     // move forward (more than) enough places to be at the end
     507             :     int i;
     508           9 :     for (i = 0; i < 8; ++i)
     509           8 :         aCursor.Move(&aOutputDevice, MoveRight);
     510             : 
     511             :     // tack +d on the end, which will put the binom into an SmBinHorNode
     512           1 :     aCursor.InsertElement(PlusElement);
     513           1 :     aCursor.InsertText("d");
     514             : 
     515           1 :     sExpected.AppendAscii(" { { binom a b + c } + d } ");
     516           1 :     CPPUNIT_ASSERT_EQUAL_MESSAGE("Binom Node in BinHor Node", sExpected, String(xDocShRef->GetText()));
     517             : 
     518           2 :     delete pTree;
     519           1 : }
     520             : 
     521           1 : void Test::testBinVerInUnary()
     522             : {
     523           2 :     String sInput, sExpected;
     524             :     SmNode* pTree;
     525             : 
     526             :     // set up a unary operator with operand
     527           1 :     sInput.AppendAscii("- 1");
     528           1 :     pTree = SmParser().Parse(sInput);
     529           1 :     pTree->Prepare(xDocShRef->GetFormat(), *xDocShRef);
     530             : 
     531           2 :     SmCursor aCursor(pTree, xDocShRef);
     532           2 :     TestOutputDevice aOutputDevice;
     533             : 
     534             :     // move forward (more than) enough places to be at the end
     535             :     int i;
     536           4 :     for (i = 0; i < 3; ++i)
     537           3 :         aCursor.Move(&aOutputDevice, MoveRight);
     538             : 
     539             :     // select the operand
     540           1 :     aCursor.Move(&aOutputDevice, MoveLeft, false);
     541             :     // set up a fraction
     542           1 :     aCursor.InsertFraction();
     543           1 :     aCursor.Move(&aOutputDevice, MoveDown);
     544           1 :     aCursor.InsertText("2");
     545             : 
     546           1 :     sExpected.AppendAscii(" - { 1 over 2 } ");
     547           1 :     CPPUNIT_ASSERT_EQUAL_MESSAGE("Binary Vertical in Unary Operator", sExpected, String(xDocShRef->GetText()));
     548             : 
     549           2 :     delete pTree;
     550           1 : }
     551             : 
     552           1 : void Test::testBinHorInSubSup()
     553             : {
     554           2 :     String sInput, sExpected;
     555             :     SmNode* pTree;
     556             : 
     557             :     // set up a blank formula
     558           1 :     sInput.AppendAscii("");
     559           1 :     pTree = SmParser().Parse(sInput);
     560           1 :     pTree->Prepare(xDocShRef->GetFormat(), *xDocShRef);
     561             : 
     562           2 :     SmCursor aCursor(pTree, xDocShRef);
     563           2 :     TestOutputDevice aOutputDevice;
     564             : 
     565             :     // Insert an RSup expression with a BinHor for the exponent
     566           1 :     aCursor.InsertText("a");
     567           1 :     aCursor.InsertSubSup(RSUP);
     568           1 :     aCursor.InsertText("b");
     569           1 :     aCursor.InsertElement(PlusElement);
     570           1 :     aCursor.InsertText("c");
     571             : 
     572             :     // Move to the end and add d to the expression
     573           1 :     aCursor.Move(&aOutputDevice, MoveRight);
     574           1 :     aCursor.InsertElement(PlusElement);
     575           1 :     aCursor.InsertText("d");
     576             : 
     577           1 :     sExpected.AppendAscii(" { a rsup { b + c } + d } ");
     578             : //FIXME    CPPUNIT_ASSERT_EQUAL_MESSAGE("BinHor in SubSup", sExpected, xDocShRef->GetText());
     579             : 
     580           2 :     delete pTree;
     581           1 : }
     582             : 
     583           1 : void Test::testUnaryInMixedNumberAsNumerator()
     584             : {
     585           2 :     String sInput, sExpected;
     586             :     SmNode* pTree;
     587             : 
     588             :     // set up a unary operator
     589           1 :     sInput.AppendAscii("- 1");
     590           1 :     pTree = SmParser().Parse(sInput);
     591           1 :     pTree->Prepare(xDocShRef->GetFormat(), *xDocShRef);
     592             : 
     593           2 :     SmCursor aCursor(pTree, xDocShRef);
     594           2 :     TestOutputDevice aOutputDevice;
     595             : 
     596             :     // move forward (more than) enough places to be at the end
     597             :     int i;
     598           4 :     for (i = 0; i < 3; ++i)
     599           3 :         aCursor.Move(&aOutputDevice, MoveRight);
     600             : 
     601             :     // Select the whole Unary Horizontal Node
     602           1 :     aCursor.Move(&aOutputDevice, MoveLeft, false);
     603           1 :     aCursor.Move(&aOutputDevice, MoveLeft, false);
     604             : 
     605             :     // Set up a fraction
     606           1 :     aCursor.InsertFraction();
     607           1 :     aCursor.Move(&aOutputDevice, MoveDown);
     608           1 :     aCursor.InsertText("2");
     609             : 
     610             :     // Move left and turn this into a mixed number
     611             :     // (bad form, but this could happen right?)
     612           1 :     aCursor.Move(&aOutputDevice, MoveLeft);
     613           1 :     aCursor.Move(&aOutputDevice, MoveLeft);
     614           1 :     aCursor.InsertText("2");
     615             : 
     616             :     // move forward (more than) enough places to be at the end
     617           9 :     for (i = 0; i < 8; ++i)
     618           8 :         aCursor.Move(&aOutputDevice, MoveRight);
     619             : 
     620             :     // add 4 to the end
     621           1 :     aCursor.InsertElement(PlusElement);
     622           1 :     aCursor.InsertText("4");
     623             : 
     624           1 :     sExpected.AppendAscii(" { 2 { - 1 over 2 } + 4 } ");
     625           1 :     CPPUNIT_ASSERT_EQUAL_MESSAGE("Unary in mixed number as Numerator", sExpected, String(xDocShRef->GetText()));
     626             : 
     627           2 :     delete pTree;
     628           1 : }
     629             : 
     630           1 : CPPUNIT_TEST_SUITE_REGISTRATION(Test);
     631             : 
     632           3 : }
     633             : 
     634             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10