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

Generated by: LCOV version 1.10