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