1 #include "yacsconfig.h"
2 #include "RuntimeSALOME.hxx"
3 #include "PythonPorts.hxx"
4 #include "CORBAPorts.hxx"
5 #include "YacsLoaderTest.hxx"
8 #include "Exception.hxx"
9 #include "Executor.hxx"
10 #include "parsers.hxx"
16 #include "YacsTrace.hxx"
18 using namespace YACS::ENGINE;
22 int driverTest(Proc* &p, const char* schema)
24 DEBTRACE("+++++++++++++++++++ BEGIN test " << schema);
25 RuntimeSALOME::setRuntime();
32 p=loader.load(schema);
33 DEBTRACE("Proc *p = " << p);
34 std::ofstream f("toto");
37 DEBTRACE("+++++++++++++++++++ BEGIN execution " << schema);
39 DEBTRACE("+++++++++++++++++++ END execution " << schema);
40 std::ofstream g("titi");
43 DEBTRACE("+++++++++++++++++++ END test " << schema);
46 catch (YACS::Exception& e)
48 DEBTRACE("YACS exception caught: ");
50 DEBTRACE("+++++++++++++++++++ END test in error " << schema);
53 catch (const std::ios_base::failure&)
55 DEBTRACE("io failure");
56 DEBTRACE("+++++++++++++++++++ END test in error " << schema);
59 catch(CORBA::SystemException& ex)
61 DEBTRACE("Caught a CORBA::SystemException.");
64 CORBA::TypeCode_var tc = tmp.type();
65 const char *p = tc->name();
74 DEBTRACE("+++++++++++++++++++ END test in error " << schema);
77 catch(omniORB::fatalException& fe)
79 DEBTRACE("Caught omniORB::fatalException:" );
80 DEBTRACE(" file: " << fe.file());
81 DEBTRACE(" line: " << fe.line());
82 DEBTRACE(" mesg: " << fe.errmsg());
83 DEBTRACE("+++++++++++++++++++ END test in error " << schema);
88 DEBTRACE("Caught unknown exception.");
89 DEBTRACE("+++++++++++++++++++ END test in error " << schema);
94 void YacsLoaderTest::setUp()
98 void YacsLoaderTest::tearDown()
102 void YacsLoaderTest::aschema()
105 int ret = driverTest(p, "samples/aschema.xml");
106 CPPUNIT_ASSERT(ret == 0);
107 CPPUNIT_ASSERT(p != 0);
110 CORBA::Double dval = 0;
112 CPPUNIT_ASSERT(p->nodeMap["c0.c1.n1"]);
113 *((OutputCorbaPort*)p->nodeMap["c0.c1.n1"]->getOutputPort("p1"))->getAny() >>= dval;
114 PyObject *data = ((OutputPyPort*)p->nodeMap["node32"]->getOutputPort("p1"))->get();
115 double val = PyFloat_AsDouble(data);
116 CPPUNIT_ASSERT_DOUBLES_EQUAL(22., dval, 1.E-12);
117 CPPUNIT_ASSERT_DOUBLES_EQUAL(20., val, 1.E-12);
122 void YacsLoaderTest::bschema()
125 int ret = driverTest(p, "samples/bschema.xml");
126 CPPUNIT_ASSERT(ret == 0);
127 DEBTRACE("Proc *p = " << p);
128 CPPUNIT_ASSERT(p != 0);
131 CORBA::Double dval = 0;
132 const char *text = "";
133 *((OutputCorbaPort*)p->nodeMap["node1"]->getOutputPort("p1"))->getAny() >>= dval;
134 *((OutputCorbaPort*)p->nodeMap["node2"]->getOutputPort("p1"))->getAny() >>= text;
135 CPPUNIT_ASSERT_DOUBLES_EQUAL(24., dval, 1.E-12);
136 CPPUNIT_ASSERT_EQUAL(string("coucou"), string(text));
141 void YacsLoaderTest::cschema()
144 int ret = driverTest(p, "samples/cschema.xml");
145 CPPUNIT_ASSERT(ret == 0);
146 DEBTRACE("Proc *p = " << p);
147 CPPUNIT_ASSERT(p != 0);
151 CORBA::Double dval = 0;
152 const char *text = "";
153 *((OutputCorbaPort*)p->nodeMap["node1"]->getOutputPort("p1"))->getAny() >>= text;
154 CPPUNIT_ASSERT_EQUAL(string("Hello coucou!"), string(text) );
156 *((OutputCorbaPort*)p->nodeMap["node2"]->getOutputPort("p1"))->getAny() >>= text;
157 CPPUNIT_ASSERT_EQUAL(string("Hello Hello coucou!!"), string(text) );
163 void YacsLoaderTest::dschema()
166 int ret = driverTest(p, "samples/dschema.xml");
167 CPPUNIT_ASSERT(ret == 0);
168 DEBTRACE("Proc *p = " << p);
169 CPPUNIT_ASSERT(p != 0);
173 CORBA::Double dval = 0;
174 const char *text = "";
175 *((OutputCorbaPort*)p->nodeMap["node1"]->getOutputPort("p1"))->getAny() >>= text;
176 CPPUNIT_ASSERT_EQUAL(string("Hello coucou!"), string(text) );
178 *((OutputCorbaPort*)p->nodeMap["node2"]->getOutputPort("p1"))->getAny() >>= text;
179 CPPUNIT_ASSERT_EQUAL(string("Hello Hello coucou!!"), string(text) );
181 *((OutputCorbaPort*)p->nodeMap["node3"]->getOutputPort("p1"))->getAny() >>= text;
182 CPPUNIT_ASSERT_EQUAL( string("Hello Hello coucou!!"), string(text));
188 void YacsLoaderTest::eschema()
191 int ret = driverTest(p, "samples/eschema.xml");
192 CPPUNIT_ASSERT(ret == 0);
193 DEBTRACE("Proc *p = " << p);
194 CPPUNIT_ASSERT(p != 0);
197 PyObject *data = ((OutputPyPort*)p->nodeMap["node2"]->getOutputPort("p1"))->get();
198 char *text = PyString_AsString(data);
199 CPPUNIT_ASSERT_EQUAL(string("coucoucoucoucoucoucoucou"), string(text));
204 void YacsLoaderTest::fschema()
207 int ret = driverTest(p, "samples/fschema.xml");
208 CPPUNIT_ASSERT(ret == 0);
209 DEBTRACE("Proc *p = " << p);
210 CPPUNIT_ASSERT(p != 0);
213 PyObject *data = ((OutputPyPort*)p->nodeMap["node2"]->getOutputPort("p1"))->get();
214 char *text = PyString_AsString(data);;
215 CPPUNIT_ASSERT_EQUAL(string("coucoucoucoucoucoucoucou"), string(text) );
220 void YacsLoaderTest::oschema()
223 int ret = driverTest(p, "samples/oschema.xml");
224 CPPUNIT_ASSERT(ret == 1);
227 void YacsLoaderTest::pschema()
230 int ret = driverTest(p, "samples/pschema.xml");
231 CPPUNIT_ASSERT(ret == 0);
232 DEBTRACE("Proc *p = " << p);
233 CPPUNIT_ASSERT(p != 0);
237 CORBA::Double dval = 0;
238 *((OutputCorbaPort*)p->nodeMap["node61"]->getOutputPort("p1"))->getAny() >>= dval;
239 CPPUNIT_ASSERT_DOUBLES_EQUAL(25., dval, 1.E-12);
242 CORBA::Double dval = 0;
243 *((OutputCorbaPort*)p->nodeMap["node62"]->getOutputPort("p1"))->getAny() >>= dval;
244 CPPUNIT_ASSERT_DOUBLES_EQUAL(25., dval, 1.E-12);
247 CORBA::Double dval = 0;
248 *((OutputCorbaPort*)p->nodeMap["node63"]->getOutputPort("p1"))->getAny() >>= dval;
249 CPPUNIT_ASSERT_DOUBLES_EQUAL(25., dval, 1.E-12);
255 void YacsLoaderTest::schema()
258 int ret = driverTest(p, "samples/schema.xml");
259 CPPUNIT_ASSERT(ret == 1);
262 void YacsLoaderTest::schema2()
265 int ret = driverTest(p, "samples/schema2.xml");
266 CPPUNIT_ASSERT(ret == 0);
267 DEBTRACE("Proc *p = " << p);
268 CPPUNIT_ASSERT(p != 0);
272 CORBA::Double dval = 0;
273 *((OutputCorbaPort*)p->nodeMap["node61"]->getOutputPort("p1"))->getAny() >>= dval;
274 CPPUNIT_ASSERT_DOUBLES_EQUAL(25., dval, 1.E-12);
277 CORBA::Double dval = 0;
278 *((OutputCorbaPort*)p->nodeMap["node62"]->getOutputPort("p1"))->getAny() >>= dval;
279 CPPUNIT_ASSERT_DOUBLES_EQUAL(25., dval, 1.E-12);
282 CORBA::Double dval = 0;
283 *((OutputCorbaPort*)p->nodeMap["node63"]->getOutputPort("p1"))->getAny() >>= dval;
284 CPPUNIT_ASSERT_DOUBLES_EQUAL(25., dval, 1.E-12);
290 void YacsLoaderTest::forloop1()
293 int ret = driverTest(p, "samples/forloop1.xml");
294 CPPUNIT_ASSERT(ret == 0);
295 DEBTRACE("Proc *p = " << p);
296 CPPUNIT_ASSERT(p != 0);
299 PyObject *data = ((OutputPyPort*)p->nodeMap["b1.node2"]->getOutputPort("p1"))->get();
300 double val = PyFloat_AsDouble(data);;
301 CPPUNIT_ASSERT_DOUBLES_EQUAL(33., val, 1.E-12);
306 void YacsLoaderTest::forloop2()
309 int ret = driverTest(p, "samples/forloop2.xml");
310 CPPUNIT_ASSERT(ret == 0);
313 /////////////////////////////
315 void YacsLoaderTest::forloop3()
318 int ret = driverTest(p, "samples/forloop3.xml");
319 CPPUNIT_ASSERT(ret == 0);
320 DEBTRACE("Proc *p = " << p);
321 CPPUNIT_ASSERT(p != 0);
324 // PyObject *data = ((OutputPyPort*)p->nodeMap["node2"]->getOutputPort("p1"))->get();
325 // char *text = PyString_AsString(data);;
326 // CPPUNIT_ASSERT_EQUAL(string(text), string("coucoucoucoucoucoucoucou"));
331 void YacsLoaderTest::forloop4()
334 int ret = driverTest(p, "samples/forloop4.xml");
335 CPPUNIT_ASSERT(ret == 0);
336 DEBTRACE("Proc *p = " << p);
337 CPPUNIT_ASSERT(p != 0);
340 // PyObject *data = ((OutputPyPort*)p->nodeMap["node2"]->getOutputPort("p1"))->get();
341 // char *text = PyString_AsString(data);;
342 // CPPUNIT_ASSERT_EQUAL(string(text), string("coucoucoucoucoucoucoucou"));
347 void YacsLoaderTest::forloop5()
350 int ret = driverTest(p, "samples/forloop5.xml");
351 CPPUNIT_ASSERT(ret == 0);
352 DEBTRACE("Proc *p = " << p);
353 CPPUNIT_ASSERT(p != 0);
356 // PyObject *data = ((OutputPyPort*)p->nodeMap["node2"]->getOutputPort("p1"))->get();
357 // char *text = PyString_AsString(data);;
358 // CPPUNIT_ASSERT_EQUAL(string(text), string("coucoucoucoucoucoucoucou"));
363 void YacsLoaderTest::forloop6()
366 int ret = driverTest(p, "samples/forloop6.xml");
367 CPPUNIT_ASSERT(ret == 0);
368 DEBTRACE("Proc *p = " << p);
369 CPPUNIT_ASSERT(p != 0);
372 // PyObject *data = ((OutputPyPort*)p->nodeMap["node2"]->getOutputPort("p1"))->get();
373 // char *text = PyString_AsString(data);;
374 // CPPUNIT_ASSERT_EQUAL(string(text), string("coucoucoucoucoucoucoucou"));
380 void YacsLoaderTest::forloop7()
383 int ret = driverTest(p, "samples/forloop7.xml");
384 CPPUNIT_ASSERT(ret == 0);
385 DEBTRACE("Proc *p = " << p);
386 CPPUNIT_ASSERT(p != 0);
389 // PyObject *data = ((OutputPyPort*)p->nodeMap["node2"]->getOutputPort("p1"))->get();
390 // char *text = PyString_AsString(data);;
391 // CPPUNIT_ASSERT_EQUAL(string(text), string("coucoucoucoucoucoucoucou"));
396 void YacsLoaderTest::switch1()
399 int ret = driverTest(p, "samples/switch1.xml");
400 CPPUNIT_ASSERT(ret == 0);
401 DEBTRACE("Proc *p = " << p);
402 CPPUNIT_ASSERT(p != 0);
405 // PyObject *data = ((OutputPyPort*)p->nodeMap["node2"]->getOutputPort("p1"))->get();
406 // char *text = PyString_AsString(data);;
407 // CPPUNIT_ASSERT_EQUAL(string(text), string("coucoucoucoucoucoucoucou"));
412 void YacsLoaderTest::switch2()
415 int ret = driverTest(p, "samples/switch2.xml");
416 CPPUNIT_ASSERT(ret == 0);
417 DEBTRACE("Proc *p = " << p);
418 CPPUNIT_ASSERT(p != 0);
421 // PyObject *data = ((OutputPyPort*)p->nodeMap["node2"]->getOutputPort("p1"))->get();
422 // char *text = PyString_AsString(data);;
423 // CPPUNIT_ASSERT_EQUAL(string(text), string("coucoucoucoucoucoucoucou"));
428 void YacsLoaderTest::switch3()
431 int ret = driverTest(p, "samples/switch3.xml");
432 CPPUNIT_ASSERT(ret == 0);
433 DEBTRACE("Proc *p = " << p);
434 CPPUNIT_ASSERT(p != 0);
437 // PyObject *data = ((OutputPyPort*)p->nodeMap["node2"]->getOutputPort("p1"))->get();
438 // char *text = PyString_AsString(data);;
439 // CPPUNIT_ASSERT_EQUAL(string(text), string("coucoucoucoucoucoucoucou"));
444 void YacsLoaderTest::switch4()
447 int ret = driverTest(p, "samples/switch4.xml");
448 CPPUNIT_ASSERT(ret == 0);
449 DEBTRACE("Proc *p = " << p);
450 CPPUNIT_ASSERT(p != 0);
453 // PyObject *data = ((OutputPyPort*)p->nodeMap["node2"]->getOutputPort("p1"))->get();
454 // char *text = PyString_AsString(data);;
455 // CPPUNIT_ASSERT_EQUAL(string(text), string("coucoucoucoucoucoucoucou"));
460 void YacsLoaderTest::switch5()
463 int ret = driverTest(p, "samples/switch5.xml");
464 CPPUNIT_ASSERT(ret == 0);
465 DEBTRACE("Proc *p = " << p);
466 CPPUNIT_ASSERT(p != 0);
469 // PyObject *data = ((OutputPyPort*)p->nodeMap["node2"]->getOutputPort("p1"))->get();
470 // char *text = PyString_AsString(data);;
471 // CPPUNIT_ASSERT_EQUAL(string(text), string("coucoucoucoucoucoucoucou"));
476 void YacsLoaderTest::switch6()
479 int ret = driverTest(p, "samples/switch6.xml");
480 CPPUNIT_ASSERT(ret == 0);
481 DEBTRACE("Proc *p = " << p);
482 CPPUNIT_ASSERT(p != 0);
485 // PyObject *data = ((OutputPyPort*)p->nodeMap["node2"]->getOutputPort("p1"))->get();
486 // char *text = PyString_AsString(data);;
487 // CPPUNIT_ASSERT_EQUAL(string(text), string("coucoucoucoucoucoucoucou"));
492 void YacsLoaderTest::switch7()
495 int ret = driverTest(p, "samples/switch7.xml");
496 CPPUNIT_ASSERT(ret == 0);
497 DEBTRACE("Proc *p = " << p);
498 CPPUNIT_ASSERT(p != 0);
501 // PyObject *data = ((OutputPyPort*)p->nodeMap["node2"]->getOutputPort("p1"))->get();
502 // char *text = PyString_AsString(data);;
503 // CPPUNIT_ASSERT_EQUAL(string(text), string("coucoucoucoucoucoucoucou"));
508 void YacsLoaderTest::switch8()
511 int ret = driverTest(p, "samples/switch8.xml");
512 CPPUNIT_ASSERT(ret == 0);
513 DEBTRACE("Proc *p = " << p);
514 CPPUNIT_ASSERT(p != 0);
517 // PyObject *data = ((OutputPyPort*)p->nodeMap["node2"]->getOutputPort("p1"))->get();
518 // char *text = PyString_AsString(data);;
519 // CPPUNIT_ASSERT_EQUAL(string(text), string("coucoucoucoucoucoucoucou"));
524 void YacsLoaderTest::switch9()
527 int ret = driverTest(p, "samples/switch9.xml");
528 CPPUNIT_ASSERT(ret == 0);
529 DEBTRACE("Proc *p = " << p);
530 CPPUNIT_ASSERT(p != 0);
533 // PyObject *data = ((OutputPyPort*)p->nodeMap["node2"]->getOutputPort("p1"))->get();
534 // char *text = PyString_AsString(data);;
535 // CPPUNIT_ASSERT_EQUAL(string(text), string("coucoucoucoucoucoucoucou"));
540 void YacsLoaderTest::whiles()
543 int ret = driverTest(p, "samples/while1.xml");
544 CPPUNIT_ASSERT(ret == 0);
545 DEBTRACE("Proc *p = " << p);
546 CPPUNIT_ASSERT(p != 0);
549 // PyObject *data = ((OutputPyPort*)p->nodeMap["node2"]->getOutputPort("p1"))->get();
550 // char *text = PyString_AsString(data);;
551 // CPPUNIT_ASSERT_EQUAL(string(text), string("coucoucoucoucoucoucoucou"));
554 ret = driverTest(p, "samples/while2.xml");
555 CPPUNIT_ASSERT(ret == 0);
556 ret = driverTest(p, "samples/while3.xml");
557 CPPUNIT_ASSERT(ret == 0);
560 void YacsLoaderTest::forwhile1()
563 int ret = driverTest(p, "samples/forwhile1.xml");
564 CPPUNIT_ASSERT(ret == 0);
565 DEBTRACE("Proc *p = " << p);
566 CPPUNIT_ASSERT(p != 0);
569 // PyObject *data = ((OutputPyPort*)p->nodeMap["node2"]->getOutputPort("p1"))->get();
570 // char *text = PyString_AsString(data);;
571 // CPPUNIT_ASSERT_EQUAL(string(text), string("coucoucoucoucoucoucoucou"));
576 void YacsLoaderTest::blocs()
580 ret = driverTest(p, "samples/bloc1.xml");
581 CPPUNIT_ASSERT(ret == 0);
582 CPPUNIT_ASSERT(p->getEffectiveState() == YACS::DONE );
583 ret = driverTest(p, "samples/bloc2.xml");
584 CPPUNIT_ASSERT(ret == 0);
585 CPPUNIT_ASSERT(p->getEffectiveState() == YACS::DONE );
586 ret = driverTest(p, "samples/bloc3.xml");
587 CPPUNIT_ASSERT(ret == 0);
588 CPPUNIT_ASSERT(p->getEffectiveState() != YACS::DONE );
589 ret = driverTest(p, "samples/bloc4.xml");
590 CPPUNIT_ASSERT(ret == 0);
591 CPPUNIT_ASSERT(p->getEffectiveState() == YACS::DONE );
594 void YacsLoaderTest::refcnt()
599 ret = driverTest(p, "samples/refcnt1.xml");
600 CPPUNIT_ASSERT(ret == 0);
601 data = ((OutputPyPort*)p->nodeMap["b1.b.node1"]->getOutputPort("p1"))->get();
602 CPPUNIT_ASSERT_EQUAL(13, data->ob_refcnt);
603 ret = driverTest(p, "samples/refcnt2.xml");
604 CPPUNIT_ASSERT(ret == 0);
605 data = ((OutputPyPort*)p->nodeMap["b1.b.node1"]->getOutputPort("p1"))->get();
606 CPPUNIT_ASSERT_EQUAL(19, data->ob_refcnt);
609 void YacsLoaderTest::foreachs()
613 ret = driverTest(p, "samples/foreach1.xml");
614 CPPUNIT_ASSERT(ret == 0);
615 CPPUNIT_ASSERT(p->getEffectiveState() == YACS::DONE );
616 ret = driverTest(p, "samples/foreach2.xml");
617 CPPUNIT_ASSERT(ret == 0);
618 CPPUNIT_ASSERT(p->getEffectiveState() == YACS::DONE );
619 ret = driverTest(p, "samples/foreach3.xml");
620 CPPUNIT_ASSERT(ret == 1);
621 ret = driverTest(p, "samples/foreach4.xml");
622 CPPUNIT_ASSERT(ret == 0);
623 CPPUNIT_ASSERT(p->getEffectiveState() == YACS::DONE );
624 ret = driverTest(p, "samples/foreach5.xml");
625 CPPUNIT_ASSERT(ret == 0);
626 CPPUNIT_ASSERT(p->getEffectiveState() == YACS::DONE );
627 ret = driverTest(p, "samples/foreach6.xml");
628 CPPUNIT_ASSERT(ret == 0);
629 CPPUNIT_ASSERT(p->getEffectiveState() == YACS::DONE );
632 void YacsLoaderTest::sinlines()
636 ret = driverTest(p, "samples/sinline1.xml");
637 CPPUNIT_ASSERT(ret == 0);
638 CPPUNIT_ASSERT(p->getEffectiveState() == YACS::DONE );
639 ret = driverTest(p, "samples/sinline2.xml");
640 CPPUNIT_ASSERT(ret == 0);
641 CPPUNIT_ASSERT(p->getEffectiveState() == YACS::DONE );
642 ret = driverTest(p, "samples/sinline3.xml");
643 CPPUNIT_ASSERT(ret == 0);
644 CPPUNIT_ASSERT(p->getEffectiveState() == YACS::DONE );
645 ret = driverTest(p, "samples/sinline4.xml");
646 CPPUNIT_ASSERT(ret == 0);
647 CPPUNIT_ASSERT(p->getEffectiveState() == YACS::DONE );
648 ret = driverTest(p, "samples/sinline5.xml");
649 CPPUNIT_ASSERT(ret == 0);
650 CPPUNIT_ASSERT(p->getEffectiveState() == YACS::DONE );
653 void YacsLoaderTest::bools()
657 ret = driverTest(p, "samples/bool1.xml");
658 CPPUNIT_ASSERT(ret == 0);
659 CPPUNIT_ASSERT(p->getEffectiveState() == YACS::DONE );
661 void YacsLoaderTest::integers()
665 ret = driverTest(p, "samples/integer1.xml");
666 CPPUNIT_ASSERT(ret == 0);
667 CPPUNIT_ASSERT(p->getEffectiveState() == YACS::DONE );
669 void YacsLoaderTest::doubles()
673 ret = driverTest(p, "samples/double1.xml");
674 CPPUNIT_ASSERT(ret == 0);
675 CPPUNIT_ASSERT(p->getEffectiveState() == YACS::DONE );
677 void YacsLoaderTest::strings()
681 ret = driverTest(p, "samples/string1.xml");
682 CPPUNIT_ASSERT(ret == 0);
683 CPPUNIT_ASSERT(p->getEffectiveState() == YACS::DONE );
685 void YacsLoaderTest::objrefs()
689 ret = driverTest(p, "samples/objref1.xml");
690 CPPUNIT_ASSERT(ret == 0);
691 CPPUNIT_ASSERT(p->getEffectiveState() == YACS::DONE );
693 void YacsLoaderTest::structs()
697 ret = driverTest(p, "samples/struct1.xml");
698 CPPUNIT_ASSERT(ret == 0);
699 CPPUNIT_ASSERT(p->getEffectiveState() == YACS::DONE );
702 ret = driverTest(p, "samples/struct2.xml");
703 CPPUNIT_ASSERT(ret == 0);
704 CPPUNIT_ASSERT(p->getEffectiveState() == YACS::DONE );
708 void YacsLoaderTest::cpps()
712 ret = driverTest(p, "samples/cpp1.xml");
713 CPPUNIT_ASSERT(ret == 0);
714 CPPUNIT_ASSERT(p->getEffectiveState() == YACS::DONE );
718 void YacsLoaderTest::datanodes()
722 ret = driverTest(p, "samples/datanode0.xml");
723 CPPUNIT_ASSERT(ret == 0);
724 CPPUNIT_ASSERT(p->getEffectiveState() == YACS::DONE );