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

Generated by: LCOV version 1.10