1 // Copyright (C) 2006-2019 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 // --- include from engine first, to avoid redifinition warning _POSIX_C_SOURCE
22 #include "TypeConversions.hxx"
24 #include "ElementaryNode.hxx"
26 #include "ForLoop.hxx"
28 #include "CppNode.hxx"
29 #include "PythonNode.hxx"
30 #include "InlineNode.hxx"
31 #include "ServiceNode.hxx"
32 #include "XMLNode.hxx"
33 #include "PythonPorts.hxx"
34 #include "XMLPorts.hxx"
35 #include "CORBAPorts.hxx"
36 #include "CppPorts.hxx"
37 #include "CppComponent.hxx"
38 #include "Executor.hxx"
40 #include "runtimeTest.hxx"
52 #include "YacsTrace.hxx"
54 using namespace YACS::ENGINE;
60 TypeCode *RuntimeTest::_tc_double = new TypeCode(Double);
61 TypeCode *RuntimeTest::_tc_int = new TypeCode(Int);
62 TypeCode *RuntimeTest::_tc_string = new TypeCode(String);
63 TypeCode *RuntimeTest::_tc = TypeCode::interfaceTc("id","name");
64 //TypeCode *RuntimeTest::_tc_obj = TypeCode::interfaceTc("eo::Obj","IDL:eo/Obj:1.0");
65 TypeCode *RuntimeTest::_tc_obj = TypeCode::interfaceTc("IDL:eo/Obj:1.0","Obj");
66 TypeCode *RuntimeTest::_tc_seqdble = TypeCode::sequenceTc("eo:seqdouble","seqdouble",RuntimeTest::_tc_double);
67 TypeCode *RuntimeTest::_tc_seqstr = TypeCode::sequenceTc("eo:seqstring","seqstring",RuntimeTest::_tc_string);
68 TypeCode *RuntimeTest::_tc_seqlong = TypeCode::sequenceTc("eo:seqlong","seqlong",RuntimeTest::_tc_int);
69 TypeCode *RuntimeTest::_tc_seqobj = TypeCode::sequenceTc("eo:seqobj","seqobj",RuntimeTest::_tc_obj);
70 TypeCode *RuntimeTest::_tc_seqseqdble= TypeCode::sequenceTc("eo:seqseqdble","seqseqdble",RuntimeTest::_tc_seqdble);
71 TypeCode *RuntimeTest::_tc_seqseqobj = TypeCode::sequenceTc("eo:seqseqobj","seqseqobj",RuntimeTest::_tc_seqobj);
73 list<TypeCodeObjref *> RuntimeTest::_ltc;
74 TypeCode *RuntimeTest::_tc_C;
75 TypeCode *RuntimeTest::_tc_seqC;
77 map<string, Node*> RuntimeTest::_nodeMap;
78 map<string, Bloc*> RuntimeTest::_blocMap;
79 int RuntimeTest::_inode = 0;
80 int RuntimeTest::_ibloc = 0;
81 Runtime *RuntimeTest::_myRuntime = 0;
82 bool RuntimeTest::endTests = false;
84 void RuntimeTest::setUp()
88 _ltc.push_back((TypeCodeObjref *)_tc_obj);
89 _tc_C = TypeCode::interfaceTc("IDL:eo/C:1.0","C",_ltc);
90 _tc_seqC = TypeCode::sequenceTc("eo:seqC","seqC",_tc_C);
95 #define cRef(x) cerr << "_tc" << #x << " : " << _tc ## x->getRefCnt() << endl
97 void RuntimeTest::tearDown()
102 void RuntimeTest::initRuntimeTypeCode()
105 std::cerr << std::endl;
106 RuntimeSALOME::setRuntime();
107 _myRuntime = getRuntime();
109 // --- init typecodes
111 DEBTRACE( " " << _tc->id() << " " << _tc->name() );
112 DEBTRACE("int is a int: "); CPPUNIT_ASSERT( _tc_int->isA(_tc_int));
113 DEBTRACE("seqdble is not a seqlong: "); CPPUNIT_ASSERT(!_tc_seqdble->isA(_tc_seqlong));
114 DEBTRACE("seqdble is a seqdble: "); CPPUNIT_ASSERT( _tc_seqdble->isA(_tc_seqdble));
115 DEBTRACE("seqlong is not a seqdble: "); CPPUNIT_ASSERT(!_tc_seqlong->isA(_tc_seqdble));
116 DEBTRACE("C is a Obj: "); CPPUNIT_ASSERT( _tc_C->isA(_tc_obj));
117 DEBTRACE("Obj is not a C: " ); CPPUNIT_ASSERT(!_tc_obj->isA(_tc_C));
118 DEBTRACE("seqC is a seqObj: "); CPPUNIT_ASSERT( _tc_seqC->isA(_tc_seqobj));
119 DEBTRACE( "seqObj is not a seqC: "); CPPUNIT_ASSERT(!_tc_seqobj->isA(_tc_seqC));
122 void RuntimeTest::createPythonNodes()
124 // --- Nodes 0 a 4 : Python
126 for (int i=0; i<5; i++)
129 ss << "Node_" << _inode++;
131 ElementaryNode* node = _myRuntime->createScriptNode("",s);
133 InputPort *i1 = node->edAddInputPort("id1", _tc_double);
134 InputPort *i2 = node->edAddInputPort("ii2", _tc_int);
135 InputPort *i3 = node->edAddInputPort("is3", _tc_string);
136 InputPort *i4 = node->edAddInputPort("io4", _tc_obj);
137 InputPort *i5 = node->edAddInputPort("isd5", _tc_seqdble);
138 InputPort *i6 = node->edAddInputPort("isl6", _tc_seqlong);
139 InputPort *i7 = node->edAddInputPort("iso7", _tc_seqobj);
140 InputPort *i8 = node->edAddInputPort("issd8",_tc_seqseqdble);
141 InputPort *i9 = node->edAddInputPort("isso9",_tc_seqseqobj);
142 InputPort *i10 = node->edAddInputPort("iC10", _tc_C);
143 InputPort *i11 = node->edAddInputPort("isC11",_tc_seqC);
145 OutputPort *o1 = node->edAddOutputPort("od1", _tc_double);
146 OutputPort *o2 = node->edAddOutputPort("oi2", _tc_int);
147 OutputPort *o3 = node->edAddOutputPort("os3", _tc_string);
148 OutputPort *o4 = node->edAddOutputPort("oo4", _tc_obj);
149 OutputPort *o5 = node->edAddOutputPort("osd5", _tc_seqdble);
150 OutputPort *o6 = node->edAddOutputPort("osl6", _tc_seqlong);
151 OutputPort *o7 = node->edAddOutputPort("oso7", _tc_seqobj);
152 OutputPort *o8 = node->edAddOutputPort("ossd8",_tc_seqseqdble);
153 OutputPort *o9 = node->edAddOutputPort("osso9",_tc_seqseqobj);
154 OutputPort *o10 = node->edAddOutputPort("oC10", _tc_C);
155 OutputPort *o11 = node->edAddOutputPort("osC11",_tc_seqC);
156 CPPUNIT_ASSERT_EQUAL(node->getImplementation(),string("Python"));
157 CPPUNIT_ASSERT_EQUAL(node->getNumberOfInputPorts(),11);
158 CPPUNIT_ASSERT_EQUAL(node->getNumberOfOutputPorts(),11);
159 CPPUNIT_ASSERT_EQUAL(node->getInPortName(i10),string("iC10"));
160 CPPUNIT_ASSERT_EQUAL(node->getOutPortName(o10),string("oC10"));
161 CPPUNIT_ASSERT_EQUAL(node->getInputPort("iC10"),i10);
162 CPPUNIT_ASSERT_EQUAL(node->getOutputPort("oC10"),o10);
167 void RuntimeTest::createCORBANodes()
169 // --- Nodes 5 a 9 : CORBA
171 for (int i=5; i<10; i++)
174 ss << "Node_" << _inode++;
176 ElementaryNode* node = _myRuntime->createRefNode("",s);
178 InputPort *i1 = node->edAddInputPort("id1", _tc_double);
179 InputPort *i2 = node->edAddInputPort("ii2", _tc_int);
180 InputPort *i3 = node->edAddInputPort("is3", _tc_string);
181 InputPort *i4 = node->edAddInputPort("io4", _tc_obj);
182 InputPort *i5 = node->edAddInputPort("isd5", _tc_seqdble);
183 InputPort *i6 = node->edAddInputPort("isl6", _tc_seqlong);
184 InputPort *i7 = node->edAddInputPort("iso7", _tc_seqobj);
185 InputPort *i8 = node->edAddInputPort("issd8",_tc_seqseqdble);
186 InputPort *i9 = node->edAddInputPort("isso9",_tc_seqseqobj);
187 InputPort *i10 = node->edAddInputPort("iC10", _tc_C);
188 InputPort *i11 = node->edAddInputPort("isC11",_tc_seqC);
190 OutputPort *o1 = node->edAddOutputPort("od1", _tc_double);
191 OutputPort *o2 = node->edAddOutputPort("oi2", _tc_int);
192 OutputPort *o3 = node->edAddOutputPort("os3", _tc_string);
193 OutputPort *o4 = node->edAddOutputPort("oo4", _tc_obj);
194 OutputPort *o5 = node->edAddOutputPort("osd5", _tc_seqdble);
195 OutputPort *o6 = node->edAddOutputPort("osl6", _tc_seqlong);
196 OutputPort *o7 = node->edAddOutputPort("oso7", _tc_seqobj);
197 OutputPort *o8 = node->edAddOutputPort("ossd8",_tc_seqseqdble);
198 OutputPort *o9 = node->edAddOutputPort("osso9",_tc_seqseqobj);
199 OutputPort *o10 = node->edAddOutputPort("oC10", _tc_C);
200 OutputPort *o11 = node->edAddOutputPort("osC11",_tc_seqC);
201 CPPUNIT_ASSERT_EQUAL(node->getImplementation(),string("CORBA"));
202 CPPUNIT_ASSERT_EQUAL(node->getNumberOfInputPorts(),11);
203 CPPUNIT_ASSERT_EQUAL(node->getNumberOfOutputPorts(),11);
204 CPPUNIT_ASSERT_EQUAL(node->getInPortName(i10),string("iC10"));
205 CPPUNIT_ASSERT_EQUAL(node->getOutPortName(o10),string("oC10"));
206 CPPUNIT_ASSERT_EQUAL(node->getInputPort("iC10"),i10);
207 CPPUNIT_ASSERT_EQUAL(node->getOutputPort("oC10"),o10);
212 void RuntimeTest::createBloc()
214 DEBTRACE(" --- create bloc, add two nodes, check constituants" );
216 // --- Bloc_0 with Node_0 and Node_1
219 ss << "Bloc_" << _ibloc++;
221 Bloc* bloc = new Bloc(s);
224 bloc->edAddChild(_nodeMap["Node_0"]);
225 bloc->edAddChild(_nodeMap["Node_1"]);
227 list<ElementaryNode *> setelem = bloc->getRecursiveConstituents();
228 CPPUNIT_ASSERT(setelem.size() == 2);
232 // --- Bloc_1 with Node_2
235 ss << "Bloc_" << _ibloc++;
237 Bloc* bloc = new Bloc(s);
240 bloc->edAddChild(_nodeMap["Node_2"]);
243 DEBTRACE(" --- add a node already used in the bloc does nothing (return false)" );
244 CPPUNIT_ASSERT( ! _blocMap["Bloc_0"]->edAddChild(_nodeMap["Node_1"]));
246 DEBTRACE(" --- add a node already used elsewhere raises exception " );
247 CPPUNIT_ASSERT_THROW(_blocMap["Bloc_1"]->edAddChild(_nodeMap["Node_1"]),
252 void RuntimeTest::createRecursiveBlocs()
254 DEBTRACE(" --- recursive blocs, check constituants" );
256 // --- Bloc_2 with Bloc_0, Bloc_1 and Node_3
259 ss << "Bloc_" << _ibloc++;
261 Bloc* bloc = new Bloc(s);
264 bloc->edAddChild(_nodeMap["Bloc_0"]); // 2 elementary nodes
265 bloc->edAddChild(_nodeMap["Bloc_1"]); // 1 elementary node
266 bloc->edAddChild(_nodeMap["Node_3"]); // 1 elementary node
270 list<ElementaryNode *> setelem = _blocMap["Bloc_2"]->getRecursiveConstituents();
271 CPPUNIT_ASSERT(setelem.size() == 4);
272 for (list<ElementaryNode*>::iterator it=setelem.begin(); it!=setelem.end(); it++)
274 DEBTRACE(" elem name = " << (*it)->getName());
280 void RuntimeTest::createDataLinks()
282 DEBTRACE(" --- create and delete data links" );
284 CPPUNIT_ASSERT(_blocMap["Bloc_0"]->getNumberOfInputPorts() == 22);
285 CPPUNIT_ASSERT_THROW(_blocMap["Bloc_0"]->edAddLink(_nodeMap["Node_0"]->getOutputPort("od1"),
286 _nodeMap["Node_1"]->getInputPort("is3")),
287 YACS::ENGINE::ConversionException);
288 CPPUNIT_ASSERT(_blocMap["Bloc_0"]->getNumberOfInputPorts() == 22);
290 _blocMap["Bloc_0"]->edAddLink(_nodeMap["Node_0"]->getOutputPort("oi2"),
291 _nodeMap["Node_1"]->getInputPort("ii2"));
292 CPPUNIT_ASSERT(_blocMap["Bloc_0"]->getNumberOfInputPorts() == 22);
294 _blocMap["Bloc_0"]->edRemoveLink(_nodeMap["Node_0"]->getOutputPort("oi2"),
295 _nodeMap["Node_1"]->getInputPort("ii2"));
296 CPPUNIT_ASSERT(_blocMap["Bloc_0"]->getNumberOfInputPorts() == 22);
300 void RuntimeTest::createPythonNodesWithScript()
302 DEBTRACE(" --- create python nodes with scripts" );
304 // --- Node 10 : Python
308 ss << "Node_" << _inode++;
310 ElementaryNode* node = _myRuntime->createScriptNode("",s);
312 ((InlineNode*) node)->setScript("a=a+1\n");
313 InputPort *i1 = node->edAddInputPort("a", _tc_double);
314 OutputPort *o1 = node->edAddOutputPort("a", _tc_double);
315 CPPUNIT_ASSERT_EQUAL(node->getImplementation(),string("Python"));
316 CPPUNIT_ASSERT_EQUAL(node->getNumberOfInputPorts(),1);
317 CPPUNIT_ASSERT_EQUAL(node->getNumberOfOutputPorts(),1);
320 // --- Node 11 : Python
324 ss << "Node_" << _inode++;
326 ElementaryNode* node = _myRuntime->createScriptNode("",s);
328 ((InlineNode*) node)->setScript("a=b+1\n"
332 "seqdble=[1.5,2.4]\n"
334 "dblevecvec=[[1.5,2.4],[6.7,7.8]]\n"
336 InputPort *i1 = node->edAddInputPort("b", _tc_double);
337 OutputPort *o1 = node->edAddOutputPort("c", _tc_double);
338 OutputPort *o2 = node->edAddOutputPort("i", _tc_int);
339 OutputPort *o3 = node->edAddOutputPort("s", _tc_string);
340 OutputPort *o4 = node->edAddOutputPort("seqdble", _tc_seqdble);
341 OutputPort *o5 = node->edAddOutputPort("dblevecvec", _tc_seqseqdble);
342 OutputPort *o6 = node->edAddOutputPort("lngvec", _tc_seqlong);
345 // --- Node 12 : Python
349 ss << "Node_" << _inode++;
351 ElementaryNode* node = _myRuntime->createScriptNode("",s);
353 ((InlineNode*) node)->setScript("a=dble+1\n"
356 InputPort *i1 = node->edAddInputPort("dble", _tc_double);
357 OutputPort *o1 = node->edAddOutputPort("dble", _tc_double);
360 // --- Node 13 : Python
364 ss << "Node_" << _inode++;
366 ElementaryNode* node = _myRuntime->createScriptNode("",s);
368 ((InlineNode*) node)->setScript("print('node 13')\n"
371 "o=ob._narrow(eo.Obj)\n"
373 "print(o.echoLong(13))\n"
377 "print('++++++++',s,'+++++++++++++')\n"
379 "seqstr=['aaa','bbb']\n"
381 "seqseqobj=[[o,o],[o,o]]\n"
384 InputPort *i1 = node->edAddInputPort("dble", _tc_double);
385 InputPort *i2 = node->edAddInputPort("lng", _tc_int);
386 InputPort *i3 = node->edAddInputPort("s", _tc_string);
387 InputPort *i4 = node->edAddInputPort("ob", _tc_obj);
388 OutputPort *o1 = node->edAddOutputPort("dble", _tc_double);
389 OutputPort *o2 = node->edAddOutputPort("s", _tc_string);
390 OutputPort *o3 = node->edAddOutputPort("lng", _tc_int);
391 OutputPort *o4 = node->edAddOutputPort("ob", _tc_obj);
392 OutputPort *o5 = node->edAddOutputPort("seqstr", _tc_seqstr);
393 OutputPort *o6 = node->edAddOutputPort("seqobj", _tc_seqobj);
394 OutputPort *o7 = node->edAddOutputPort("seqseqobj", _tc_seqseqobj);
395 CPPUNIT_ASSERT_EQUAL(((InputPyPort *)i1)->getPyObj(), Py_None);
396 CPPUNIT_ASSERT_EQUAL(((InputPyPort *)i2)->getPyObj(), Py_None);
397 CPPUNIT_ASSERT_EQUAL(((InputPyPort *)i3)->getPyObj(), Py_None);
398 CPPUNIT_ASSERT_EQUAL(((InputPyPort *)i4)->getPyObj(), Py_None);
399 CPPUNIT_ASSERT_EQUAL(((OutputPyPort *)o1)->get(), Py_None);
400 CPPUNIT_ASSERT_EQUAL(((OutputPyPort *)o2)->get(), Py_None);
401 CPPUNIT_ASSERT_EQUAL(((OutputPyPort *)o3)->get(), Py_None);
402 CPPUNIT_ASSERT_EQUAL(((OutputPyPort *)o4)->get(), Py_None);
403 CPPUNIT_ASSERT_EQUAL(((OutputPyPort *)o5)->get(), Py_None);
404 CPPUNIT_ASSERT_EQUAL(((OutputPyPort *)o6)->get(), Py_None);
405 CPPUNIT_ASSERT_EQUAL(((OutputPyPort *)o7)->get(), Py_None);
408 // --- Node 14 : Python
412 ss << "Node_" << _inode++;
414 ElementaryNode* node = _myRuntime->createScriptNode("",s);
416 ((InlineNode*) node)->setScript("print(li)\n"
417 "print('lili=',lili)\n"
418 "print('lstr=',lstr)\n"
419 "print('lobj=',lobj)\n"
420 "print('llobj=',llobj)\n"
421 "print('objc=',objc)\n"
424 InputPort *i1 = node->edAddInputPort("li", _tc_seqdble);
425 InputPort *i2 = node->edAddInputPort("lili", _tc_seqseqdble);
426 InputPort *i3 = node->edAddInputPort("lstr", _tc_seqstr);
427 InputPort *i4 = node->edAddInputPort("lobj", _tc_seqobj);
428 InputPort *i5 = node->edAddInputPort("llobj", _tc_seqseqobj);
429 InputPort *i6 = node->edAddInputPort("objc", _tc_C);
430 OutputPort *o1 = node->edAddOutputPort("li", _tc_seqdble);
431 OutputPort *o2 = node->edAddOutputPort("objc", _tc_C);
432 CPPUNIT_ASSERT_EQUAL(((InputPyPort *)i1)->getPyObj(), Py_None);
433 CPPUNIT_ASSERT_EQUAL(((InputPyPort *)i2)->getPyObj(), Py_None);
434 CPPUNIT_ASSERT_EQUAL(((InputPyPort *)i3)->getPyObj(), Py_None);
435 CPPUNIT_ASSERT_EQUAL(((InputPyPort *)i4)->getPyObj(), Py_None);
436 CPPUNIT_ASSERT_EQUAL(((InputPyPort *)i5)->getPyObj(), Py_None);
437 CPPUNIT_ASSERT_EQUAL(((InputPyPort *)i6)->getPyObj(), Py_None);
438 CPPUNIT_ASSERT_EQUAL(((OutputPyPort *)o1)->get(), Py_None);
439 CPPUNIT_ASSERT_EQUAL(((OutputPyPort *)o2)->get(), Py_None);
442 // --- Node 15 : Python
446 ss << "Node_" << _inode++;
448 ElementaryNode* node = _myRuntime->createScriptNode("",s);
450 ((InlineNode*) node)->setScript("print(li)\n"
451 "li=[2*e for e in li]\n"
452 "print('obj=',obj)\n"
457 InputPort *i1 = node->edAddInputPort("li", _tc_seqdble);
458 InputPort *i2 = node->edAddInputPort("obj", _tc_obj);
459 InputPort *i3 = node->edAddInputPort("lngvec", _tc_seqlong);
460 InputPort *i4 = node->edAddInputPort("dblevec", _tc_seqdble);
461 OutputPort *o1 = node->edAddOutputPort("li", _tc_seqdble);
462 CPPUNIT_ASSERT_EQUAL(node->getImplementation(),string("Python"));
463 CPPUNIT_ASSERT_EQUAL(node->getNumberOfInputPorts(),4);
464 CPPUNIT_ASSERT_EQUAL(node->getNumberOfOutputPorts(),1);
468 void RuntimeTest::createCORBANodesWithMethod()
470 DEBTRACE(" --- create CORBA nodes" );
472 // --- Node 16 : CORBA
476 ss << "Node_" << _inode++;
478 ElementaryNode* node = _myRuntime->createRefNode("",s);
480 ((ServiceNode *) node)->setRef("corbaname:rir:#test.my_context/Echo.Object");
481 ((ServiceNode *) node)->setMethod("echoDouble");
482 InputPort *i1 = node->edAddInputPort("a", _tc_double);
483 OutputPort *o1 = node->edAddOutputPort("c", _tc_double);
484 CPPUNIT_ASSERT_EQUAL(node->getImplementation(),string("CORBA"));
485 CPPUNIT_ASSERT_EQUAL(node->getNumberOfInputPorts(),1);
486 CPPUNIT_ASSERT_EQUAL(node->getNumberOfOutputPorts(),1);
487 CPPUNIT_ASSERT_EQUAL(((InputCorbaPort *)i1)->getAny()->type()->kind(),CORBA::tk_null);
488 CPPUNIT_ASSERT_EQUAL(((OutputCorbaPort *)o1)->getAny()->type()->kind(),CORBA::tk_null);
491 // --- Node 17 - 18 : CORBA
493 for (int i =0; i <2; i++)
496 ss << "Node_" << _inode++;
498 ElementaryNode* node = _myRuntime->createRefNode("",s);
500 ((ServiceNode *) node)->setRef("corbaname:rir:#test.my_context/Echo.Object");
501 ((ServiceNode *) node)->setMethod("echoDouble");
502 InputPort *i1 = node->edAddInputPort("b", _tc_double);
503 OutputPort *o1 = node->edAddOutputPort("c", _tc_double);
506 // --- Node 19 : CORBA
510 ss << "Node_" << _inode++;
512 ElementaryNode* node = _myRuntime->createRefNode("",s);
514 ((ServiceNode *) node)->setRef("corbaname:rir:#test.my_context/Echo.Object");
515 ((ServiceNode *) node)->setMethod("createObj");
516 InputPort *i1 = node->edAddInputPort("long", _tc_int);
517 OutputPort *o1 = node->edAddOutputPort("obj", _tc_obj);
518 CPPUNIT_ASSERT_EQUAL(((InputCorbaPort *)i1)->getAny()->type()->kind(),CORBA::tk_null);
519 CPPUNIT_ASSERT_EQUAL(((OutputCorbaPort *)o1)->getAny()->type()->kind(),CORBA::tk_null);
522 // --- Node 20, 21, 22 : CORBA
524 for (int i =0; i <3; i++)
527 ss << "Node_" << _inode++;
529 ElementaryNode* node = _myRuntime->createRefNode("",s);
531 ((ServiceNode *) node)->setRef("corbaname:rir:#test.my_context/Echo.Object");
532 ((ServiceNode *) node)->setMethod("echoAll");
533 InputPort *i1 = node->edAddInputPort("double", _tc_double);
534 InputPort *i2 = node->edAddInputPort("long", _tc_int);
535 InputPort *i3 = node->edAddInputPort("str", _tc_string);
536 InputPort *i4 = node->edAddInputPort("obj", _tc_obj);
537 OutputPort *o1 = node->edAddOutputPort("double", _tc_double);
538 OutputPort *o2 = node->edAddOutputPort("long", _tc_int);
539 OutputPort *o3 = node->edAddOutputPort("str", _tc_string);
540 OutputPort *o4 = node->edAddOutputPort("obj", _tc_obj);
541 CPPUNIT_ASSERT_EQUAL(((InputCorbaPort *)i3)->getAny()->type()->kind(),CORBA::tk_null);
542 CPPUNIT_ASSERT_EQUAL(((InputCorbaPort *)i4)->getAny()->type()->kind(),CORBA::tk_null);
543 CPPUNIT_ASSERT_EQUAL(((OutputCorbaPort *)o3)->getAny()->type()->kind(),CORBA::tk_null);
544 CPPUNIT_ASSERT_EQUAL(((OutputCorbaPort *)o4)->getAny()->type()->kind(),CORBA::tk_null);
547 // --- Node 23 a 26 : CORBA
549 for (int i =0; i <4; i++)
552 ss << "Node_" << _inode++;
554 ElementaryNode* node = _myRuntime->createRefNode("",s);
556 ((ServiceNode *) node)->setRef("corbaname:rir:#test.my_context/Echo.Object");
557 ((ServiceNode *) node)->setMethod("echoDoubleVec");
558 InputPort *i1 = node->edAddInputPort("dblevec", _tc_seqdble);
559 OutputPort *o1 = node->edAddOutputPort("dblevec", _tc_seqdble);
560 CPPUNIT_ASSERT_EQUAL(((InputCorbaPort *)i1)->getAny()->type()->kind(),CORBA::tk_null);
561 CPPUNIT_ASSERT_EQUAL(((OutputCorbaPort *)o1)->getAny()->type()->kind(),CORBA::tk_null);
564 // --- Node 27 : CORBA
568 ss << "Node_" << _inode++;
570 ElementaryNode* node = _myRuntime->createRefNode("",s);
572 ((ServiceNode *) node)->setRef("corbaname:rir:#test.my_context/Echo.Object");
573 ((ServiceNode *) node)->setMethod("echoStrVec");
574 InputPort *i1 = node->edAddInputPort("strvec", _tc_seqstr);
575 OutputPort *o1 = node->edAddOutputPort("strvec", _tc_seqstr);
576 CPPUNIT_ASSERT_EQUAL(((InputCorbaPort *)i1)->getAny()->type()->kind(),CORBA::tk_null);
577 CPPUNIT_ASSERT_EQUAL(((OutputCorbaPort *)o1)->getAny()->type()->kind(),CORBA::tk_null);
580 // --- Node 28 : CORBA
584 ss << "Node_" << _inode++;
586 ElementaryNode* node = _myRuntime->createRefNode("",s);
588 ((ServiceNode *) node)->setRef("corbaname:rir:#test.my_context/Echo.Object");
589 ((ServiceNode *) node)->setMethod("echoObjectVec");
590 InputPort *i1 = node->edAddInputPort("objvec", _tc_seqobj);
591 OutputPort *o1 = node->edAddOutputPort("objvec", _tc_seqobj);
592 CPPUNIT_ASSERT_EQUAL(((InputCorbaPort *)i1)->getAny()->type()->kind(),CORBA::tk_null);
593 CPPUNIT_ASSERT_EQUAL(((OutputCorbaPort *)o1)->getAny()->type()->kind(),CORBA::tk_null);
596 // --- Node 29 : CORBA
600 ss << "Node_" << _inode++;
602 ElementaryNode* node = _myRuntime->createRefNode("",s);
604 ((ServiceNode *) node)->setRef("corbaname:rir:#test.my_context/Echo.Object");
605 ((ServiceNode *) node)->setMethod("echoDoubleVecVec");
606 InputPort *i1 = node->edAddInputPort("dblevecvec", _tc_seqseqdble);
607 OutputPort *o1 = node->edAddOutputPort("dblevecvec", _tc_seqseqdble);
608 CPPUNIT_ASSERT_EQUAL(((InputCorbaPort *)i1)->getAny()->type()->kind(),CORBA::tk_null);
609 CPPUNIT_ASSERT_EQUAL(((OutputCorbaPort *)o1)->getAny()->type()->kind(),CORBA::tk_null);
612 // --- Node 30 : CORBA
616 ss << "Node_" << _inode++;
618 ElementaryNode* node = _myRuntime->createRefNode("",s);
620 ((ServiceNode *) node)->setRef("corbaname:rir:#test.my_context/Echo.Object");
621 ((ServiceNode *) node)->setMethod("echoObjectVecVec");
622 InputPort *i1 = node->edAddInputPort("objvecvec", _tc_seqseqobj);
623 OutputPort *o1 = node->edAddOutputPort("objvecvec", _tc_seqseqobj);
624 CPPUNIT_ASSERT_EQUAL(((InputCorbaPort *)i1)->getAny()->type()->kind(),CORBA::tk_null);
625 CPPUNIT_ASSERT_EQUAL(((OutputCorbaPort *)o1)->getAny()->type()->kind(),CORBA::tk_null);
628 // --- Node 31 : CORBA
632 ss << "Node_" << _inode++;
634 ElementaryNode* node = _myRuntime->createRefNode("",s);
636 ((ServiceNode *) node)->setRef("corbaname:rir:#test.my_context/Echo.Object");
637 ((ServiceNode *) node)->setMethod("echoIntVec");
638 InputPort *i1 = node->edAddInputPort("lngvec", _tc_seqlong);
639 OutputPort *o1 = node->edAddOutputPort("lngvec", _tc_seqlong);
640 CPPUNIT_ASSERT_EQUAL(((InputCorbaPort *)i1)->getAny()->type()->kind(),CORBA::tk_null);
641 CPPUNIT_ASSERT_EQUAL(((OutputCorbaPort *)o1)->getAny()->type()->kind(),CORBA::tk_null);
644 // --- Node 32 : CORBA
648 ss << "Node_" << _inode++;
650 ElementaryNode* node = _myRuntime->createRefNode("",s);
652 ((ServiceNode *) node)->setRef("corbaname:rir:#test.my_context/Echo.Object");
653 ((ServiceNode *) node)->setMethod("createC");
654 OutputPort *o1 = node->edAddOutputPort("objc", _tc_C);
655 CPPUNIT_ASSERT_EQUAL(((OutputCorbaPort *)o1)->getAny()->type()->kind(),CORBA::tk_null);
658 // --- Node 33 : CORBA
662 ss << "Node_" << _inode++;
664 ElementaryNode* node = _myRuntime->createRefNode("",s);
666 ((ServiceNode *) node)->setRef("corbaname:rir:#test.my_context/Echo.Object");
667 ((ServiceNode *) node)->setMethod("echoDouble");
668 InputPort *i1 = node->edAddInputPort("dble", _tc_double);
669 OutputPort *o1 = node->edAddOutputPort("dble", _tc_double);
672 // --- Node 34 : CORBA
676 ss << "Node_" << _inode++;
678 ElementaryNode* node = _myRuntime->createRefNode("",s);
680 ((ServiceNode *) node)->setRef("corbaname:rir:#test.my_context/Echo.Object");
681 ((ServiceNode *) node)->setMethod("echoDoubleVec");
682 InputPort *i1 = node->edAddInputPort("dblevec", _tc_seqdble);
683 OutputPort *o1 = node->edAddOutputPort("dblevec", _tc_seqdble);
686 // --- Node 35 : CORBA
690 ss << "Node_" << _inode++;
692 ElementaryNode* node = _myRuntime->createRefNode("",s);
694 ((ServiceNode *) node)->setRef("corbaname:rir:#test.my_context/Echo.Object");
695 ((ServiceNode *) node)->setMethod("echoDoubleVecVec");
696 InputPort *i1 = node->edAddInputPort("dblevecvec", _tc_seqseqdble);
697 OutputPort *o1 = node->edAddOutputPort("dblevecvec", _tc_seqseqdble);
702 void RuntimeTest::createXMLNodes()
704 DEBTRACE(" --- create XML nodes" );
710 ss << "Node_" << _inode++;
712 ElementaryNode* node = _myRuntime->createRefNode("xmlsh",s);
714 ((ServiceNode *) node)->setRef("./xmlrun.sh");
715 ((ServiceNode *) node)->setMethod("echo");
716 InputPort *i1 = node->edAddInputPort("dble", _tc_double);
717 InputPort *i2 = node->edAddInputPort("dblevec", _tc_seqdble);
718 InputPort *i3 = node->edAddInputPort("dblevecvec", _tc_seqseqdble);
719 OutputPort *o1 = node->edAddOutputPort("dble", _tc_double);
720 OutputPort *o2 = node->edAddOutputPort("dblevec", _tc_seqdble);
721 OutputPort *o3 = node->edAddOutputPort("dblevecvec", _tc_seqseqdble);
722 CPPUNIT_ASSERT_EQUAL(node->getImplementation(),string("XML"));
723 CPPUNIT_ASSERT_EQUAL(node->getNumberOfInputPorts(),3);
724 CPPUNIT_ASSERT_EQUAL(node->getNumberOfOutputPorts(),3);
729 void RuntimeTest::createBloc2()
731 DEBTRACE(" --- create Bloc with all nodes" );
733 // --- Bloc_3 with Node_10 and following
737 ss << "Bloc_" << _ibloc++;
739 Bloc* bloc = new Bloc(s);
742 for (int i=10; i<_inode; i++)
746 string sn = ssn.str();
748 bloc->edAddChild(_nodeMap[sn]);
751 list<ElementaryNode *> setelem = bloc->getRecursiveConstituents();
752 CPPUNIT_ASSERT(setelem.size() == _inode - 10);
755 set<InputPort *> unitialized = _blocMap["Bloc_3"]->edGetSetOfUnitializedInputPort();
756 DEBTRACE(unitialized.size());
757 CPPUNIT_ASSERT(! _blocMap["Bloc_3"]->edAreAllInputPortInitialized() );
761 void RuntimeTest::createDataLinksPythonPython()
763 DEBTRACE(" --- create data links, python to python" );
766 _blocMap["Bloc_3"]->edAddLink(_nodeMap["Node_10"]->getOutputPort("a"),
767 _nodeMap["Node_11"]->getInputPort("b"));
770 _blocMap["Bloc_3"]->edAddLink(_nodeMap["Node_10"]->getOutputPort("a"),
771 _nodeMap["Node_12"]->getInputPort("dble"));
773 // --- Python sequence<double> -> Python sequence<double>
774 _blocMap["Bloc_3"]->edAddLink(_nodeMap["Node_14"]->getOutputPort("li"),
775 _nodeMap["Node_15"]->getInputPort("li"));
777 // --- Python obj C (derived from Obj) -> Python obj Obj : accepted
778 _blocMap["Bloc_3"]->edAddLink(_nodeMap["Node_14"]->getOutputPort("objc"),
779 _nodeMap["Node_15"]->getInputPort("obj"));
781 // --- Python Obj -> Python C (derived from Obj) : forbidden
782 CPPUNIT_ASSERT_THROW(_blocMap["Bloc_3"]->edAddLink(_nodeMap["Node_13"]->getOutputPort("ob"),
783 _nodeMap["Node_14"]->getInputPort("objc")),
784 YACS::ENGINE::ConversionException);
786 CPPUNIT_ASSERT_THROW(_blocMap["Bloc_3"]->edAddLink(_nodeMap["Node_11"]->getOutputPort("s"),
787 _nodeMap["Node_12"]->getInputPort("dble")),
788 YACS::ENGINE::ConversionException);
790 CPPUNIT_ASSERT_THROW(_blocMap["Bloc_3"]->edAddLink(_nodeMap["Node_11"]->getOutputPort("seqdble"),
791 _nodeMap["Node_12"]->getInputPort("dble")),
792 YACS::ENGINE::ConversionException);
796 void RuntimeTest::createDataLinksPythonCORBA()
798 DEBTRACE(" --- create data links, python to CORBA" );
800 // --- double->double
801 _blocMap["Bloc_3"]->edAddLink(_nodeMap["Node_11"]->getOutputPort("c"),
802 _nodeMap["Node_16"]->getInputPort("a"));
805 _blocMap["Bloc_3"]->edAddLink(_nodeMap["Node_11"]->getOutputPort("i"),
806 _nodeMap["Node_19"]->getInputPort("long"));
809 _blocMap["Bloc_3"]->edAddLink(_nodeMap["Node_11"]->getOutputPort("s"),
810 _nodeMap["Node_20"]->getInputPort("str"));
811 cerr << "##### 3" << endl;
813 // --- seq<long> -> seq<double>
814 _blocMap["Bloc_3"]->edAddLink(_nodeMap["Node_11"]->getOutputPort("lngvec"),
815 _nodeMap["Node_23"]->getInputPort("dblevec"));
817 // --- seq<long> -> seq<long>
818 _blocMap["Bloc_3"]->edAddLink(_nodeMap["Node_11"]->getOutputPort("lngvec"),
819 _nodeMap["Node_31"]->getInputPort("lngvec"));
821 _blocMap["Bloc_3"]->edAddLink(_nodeMap["Node_13"]->getOutputPort("ob"),
822 _nodeMap["Node_22"]->getInputPort("obj"));
824 _blocMap["Bloc_3"]->edAddLink(_nodeMap["Node_11"]->getOutputPort("seqdble"),
825 _nodeMap["Node_26"]->getInputPort("dblevec"));
827 _blocMap["Bloc_3"]->edAddLink(_nodeMap["Node_13"]->getOutputPort("seqstr"),
828 _nodeMap["Node_27"]->getInputPort("strvec"));
830 _blocMap["Bloc_3"]->edAddLink(_nodeMap["Node_13"]->getOutputPort("seqobj"),
831 _nodeMap["Node_28"]->getInputPort("objvec"));
833 _blocMap["Bloc_3"]->edAddLink(_nodeMap["Node_11"]->getOutputPort("dblevecvec"),
834 _nodeMap["Node_29"]->getInputPort("dblevecvec"));
836 _blocMap["Bloc_3"]->edAddLink(_nodeMap["Node_13"]->getOutputPort("seqseqobj"),
837 _nodeMap["Node_30"]->getInputPort("objvecvec"));
839 CPPUNIT_ASSERT_THROW(_blocMap["Bloc_3"]->edAddLink(_nodeMap["Node_11"]->getOutputPort("seqdble"),
840 _nodeMap["Node_27"]->getInputPort("strvec")),
841 YACS::ENGINE::ConversionException);
843 CPPUNIT_ASSERT_THROW(_blocMap["Bloc_3"]->edAddLink(_nodeMap["Node_13"]->getOutputPort("ob"),
844 _nodeMap["Node_22"]->getInputPort("str")),
845 YACS::ENGINE::ConversionException);
847 CPPUNIT_ASSERT_THROW(_blocMap["Bloc_3"]->edAddLink(_nodeMap["Node_13"]->getOutputPort("dble"),
848 _nodeMap["Node_22"]->getInputPort("str")),
849 YACS::ENGINE::ConversionException);
851 CPPUNIT_ASSERT_THROW(_blocMap["Bloc_3"]->edAddLink(_nodeMap["Node_13"]->getOutputPort("lng"),
852 _nodeMap["Node_22"]->getInputPort("str")),
853 YACS::ENGINE::ConversionException);
855 CPPUNIT_ASSERT_THROW(_blocMap["Bloc_3"]->edAddLink(_nodeMap["Node_13"]->getOutputPort("dble"),
856 _nodeMap["Node_22"]->getInputPort("long")),
857 YACS::ENGINE::ConversionException);
859 CPPUNIT_ASSERT_THROW(_blocMap["Bloc_3"]->edAddLink(_nodeMap["Node_13"]->getOutputPort("dble"),
860 _nodeMap["Node_24"]->getInputPort("dblevec")),
861 YACS::ENGINE::ConversionException);
863 CPPUNIT_ASSERT_THROW(_blocMap["Bloc_3"]->edAddLink(_nodeMap["Node_11"]->getOutputPort("dblevecvec"),
864 _nodeMap["Node_24"]->getInputPort("dblevec")),
865 YACS::ENGINE::ConversionException);
867 CPPUNIT_ASSERT_THROW(_blocMap["Bloc_3"]->edAddLink(_nodeMap["Node_13"]->getOutputPort("seqstr"),
868 _nodeMap["Node_24"]->getInputPort("dblevec")),
869 YACS::ENGINE::ConversionException);
873 void RuntimeTest::createDataLinksCORBACORBA()
875 DEBTRACE(" --- create data links, CORBA to CORBA" );
878 _blocMap["Bloc_3"]->edAddLink(_nodeMap["Node_16"]->getOutputPort("c"),
879 _nodeMap["Node_17"]->getInputPort("b"));
882 _blocMap["Bloc_3"]->edAddLink(_nodeMap["Node_16"]->getOutputPort("c"),
883 _nodeMap["Node_18"]->getInputPort("b"));
885 CPPUNIT_ASSERT_THROW(_blocMap["Bloc_3"]->edAddLink(_nodeMap["Node_19"]->getOutputPort("obj"),
886 _nodeMap["Node_21"]->getInputPort("double")),
887 YACS::ENGINE::ConversionException);
889 CPPUNIT_ASSERT_THROW(_blocMap["Bloc_3"]->edAddLink(_nodeMap["Node_23"]->getOutputPort("dblevec"),
890 _nodeMap["Node_31"]->getInputPort("lngvec")),
891 YACS::ENGINE::ConversionException);
893 CPPUNIT_ASSERT_THROW(_blocMap["Bloc_3"]->edAddLink(_nodeMap["Node_20"]->getOutputPort("str"),
894 _nodeMap["Node_27"]->getInputPort("strvec")),
895 YACS::ENGINE::ConversionException);
897 _blocMap["Bloc_3"]->edAddLink(_nodeMap["Node_19"]->getOutputPort("obj"),
898 _nodeMap["Node_20"]->getInputPort("obj"));
900 _blocMap["Bloc_3"]->edAddLink(_nodeMap["Node_18"]->getOutputPort("c"),
901 _nodeMap["Node_20"]->getInputPort("double"));
903 _blocMap["Bloc_3"]->edAddLink(_nodeMap["Node_20"]->getOutputPort("long"),
904 _nodeMap["Node_21"]->getInputPort("double"));
906 _blocMap["Bloc_3"]->edAddLink(_nodeMap["Node_20"]->getOutputPort("long"),
907 _nodeMap["Node_21"]->getInputPort("long"));
909 _blocMap["Bloc_3"]->edAddLink(_nodeMap["Node_20"]->getOutputPort("str"),
910 _nodeMap["Node_21"]->getInputPort("str"));
912 _blocMap["Bloc_3"]->edAddLink(_nodeMap["Node_20"]->getOutputPort("obj"),
913 _nodeMap["Node_21"]->getInputPort("obj"));
915 // Corba sequence<double> -> Corba sequence<double>
916 _blocMap["Bloc_3"]->edAddLink(_nodeMap["Node_23"]->getOutputPort("dblevec"),
917 _nodeMap["Node_24"]->getInputPort("dblevec"));
919 // Corba sequence<double> -> Corba sequence<double>
920 _blocMap["Bloc_3"]->edAddLink(_nodeMap["Node_31"]->getOutputPort("lngvec"),
921 _nodeMap["Node_25"]->getInputPort("dblevec"));
923 _blocMap["Bloc_3"]->edAddLink(_nodeMap["Node_20"]->getOutputPort("long"),
924 _nodeMap["Node_22"]->getInputPort("double"));
926 _blocMap["Bloc_3"]->edAddLink(_nodeMap["Node_20"]->getOutputPort("long"),
927 _nodeMap["Node_22"]->getInputPort("long"));
929 _blocMap["Bloc_3"]->edAddLink(_nodeMap["Node_20"]->getOutputPort("str"),
930 _nodeMap["Node_22"]->getInputPort("str"));
934 void RuntimeTest::createDataLinksCORBAPython()
936 DEBTRACE(" --- create data links, CORBA to Python" );
938 CPPUNIT_ASSERT_THROW(_blocMap["Bloc_3"]->edAddLink(_nodeMap["Node_20"]->getOutputPort("double"),
939 _nodeMap["Node_13"]->getInputPort("lng")),
940 YACS::ENGINE::ConversionException);
942 CPPUNIT_ASSERT_THROW(_blocMap["Bloc_3"]->edAddLink(_nodeMap["Node_27"]->getOutputPort("strvec"),
943 _nodeMap["Node_13"]->getInputPort("s")),
944 YACS::ENGINE::ConversionException);
947 // Corba C -> Python C (derived from Obj):OK
948 _blocMap["Bloc_3"]->edAddLink(_nodeMap["Node_32"]->getOutputPort("objc"),
949 _nodeMap["Node_14"]->getInputPort("objc"));
951 _blocMap["Bloc_3"]->edAddLink(_nodeMap["Node_21"]->getOutputPort("double"),
952 _nodeMap["Node_13"]->getInputPort("dble"));
954 _blocMap["Bloc_3"]->edAddLink(_nodeMap["Node_21"]->getOutputPort("long"),
955 _nodeMap["Node_13"]->getInputPort("lng"));
957 _blocMap["Bloc_3"]->edAddLink(_nodeMap["Node_21"]->getOutputPort("str"),
958 _nodeMap["Node_13"]->getInputPort("s"));
960 _blocMap["Bloc_3"]->edAddLink(_nodeMap["Node_21"]->getOutputPort("obj"),
961 _nodeMap["Node_13"]->getInputPort("ob"));
963 // --- Corba sequence<double> -> Python sequence<double>
964 _blocMap["Bloc_3"]->edAddLink(_nodeMap["Node_23"]->getOutputPort("dblevec"),
965 _nodeMap["Node_14"]->getInputPort("li"));
967 // --- Corba sequence<sequence<double>> -> Python sequence<sequence<double>>
968 _blocMap["Bloc_3"]->edAddLink(_nodeMap["Node_29"]->getOutputPort("dblevecvec"),
969 _nodeMap["Node_14"]->getInputPort("lili"));
971 // --- Corba sequence<object> -> Python sequence<object>
972 _blocMap["Bloc_3"]->edAddLink(_nodeMap["Node_28"]->getOutputPort("objvec"),
973 _nodeMap["Node_14"]->getInputPort("lobj"));
975 // --- Corba sequence<string> -> Python sequence<string>
976 _blocMap["Bloc_3"]->edAddLink(_nodeMap["Node_27"]->getOutputPort("strvec"),
977 _nodeMap["Node_14"]->getInputPort("lstr"));
979 // --- Corba sequence<object> -> Python sequence<object>
980 _blocMap["Bloc_3"]->edAddLink(_nodeMap["Node_30"]->getOutputPort("objvecvec"),
981 _nodeMap["Node_14"]->getInputPort("llobj"));
983 _blocMap["Bloc_3"]->edAddLink(_nodeMap["Node_31"]->getOutputPort("lngvec"),
984 _nodeMap["Node_15"]->getInputPort("lngvec"));
986 _blocMap["Bloc_3"]->edAddLink(_nodeMap["Node_31"]->getOutputPort("lngvec"),
987 _nodeMap["Node_15"]->getInputPort("dblevec"));
991 void RuntimeTest::createDataLinksXML()
993 DEBTRACE(" --- create data links, xml nodes" );
995 CPPUNIT_ASSERT_THROW(_blocMap["Bloc_3"]->edAddLink(_nodeMap["Node_16"]->getOutputPort("c"),
996 _nodeMap["Node_36"]->getInputPort("dblevec")),
997 YACS::ENGINE::ConversionException);
999 CPPUNIT_ASSERT_THROW(_blocMap["Bloc_3"]->edAddLink(_nodeMap["Node_26"]->getOutputPort("dblevec"),
1000 _nodeMap["Node_36"]->getInputPort("dble")),
1001 YACS::ENGINE::ConversionException);
1003 CPPUNIT_ASSERT_THROW(_blocMap["Bloc_3"]->edAddLink(_nodeMap["Node_36"]->getOutputPort("dblevec"),
1004 _nodeMap["Node_33"]->getInputPort("dble")),
1005 YACS::ENGINE::ConversionException);
1007 CPPUNIT_ASSERT_THROW(_blocMap["Bloc_3"]->edAddLink(_nodeMap["Node_36"]->getOutputPort("dble"),
1008 _nodeMap["Node_34"]->getInputPort("dblevec")),
1009 YACS::ENGINE::ConversionException);
1011 _blocMap["Bloc_3"]->edAddLink(_nodeMap["Node_16"]->getOutputPort("c"),
1012 _nodeMap["Node_36"]->getInputPort("dble"));
1014 _blocMap["Bloc_3"]->edAddLink(_nodeMap["Node_26"]->getOutputPort("dblevec"),
1015 _nodeMap["Node_36"]->getInputPort("dblevec"));
1017 _blocMap["Bloc_3"]->edAddLink(_nodeMap["Node_29"]->getOutputPort("dblevecvec"),
1018 _nodeMap["Node_36"]->getInputPort("dblevecvec"));
1020 _blocMap["Bloc_3"]->edAddLink(_nodeMap["Node_36"]->getOutputPort("dble"),
1021 _nodeMap["Node_33"]->getInputPort("dble"));
1023 _blocMap["Bloc_3"]->edAddLink(_nodeMap["Node_36"]->getOutputPort("dblevec"),
1024 _nodeMap["Node_34"]->getInputPort("dblevec"));
1026 _blocMap["Bloc_3"]->edAddLink(_nodeMap["Node_36"]->getOutputPort("dblevecvec"),
1027 _nodeMap["Node_35"]->getInputPort("dblevecvec"));
1031 void RuntimeTest::manualInitInputPort()
1033 DEBTRACE(" --- InputPort initialization" );
1036 CPPUNIT_ASSERT(! _blocMap["Bloc_3"]->edAreAllInputPortInitialized() );
1037 set<InputPort *> unitialized = _blocMap["Bloc_3"]->edGetSetOfUnitializedInputPort();
1038 DEBTRACE(unitialized.size());
1039 for (set<InputPort *>::const_iterator iter = unitialized.begin(); iter != unitialized.end(); iter++)
1041 DEBTRACE(_blocMap["Bloc_3"]->getInPortName(*iter));
1044 _nodeMap["Node_10"]->getInputPort("a")->edInit(10.51);
1046 // CORBA::Any anyLong;
1047 // anyLong <<= (CORBA::Long) 1;
1049 _nodeMap["Node_20"]->getInputPort("long")->edInit(1);
1052 // --- manual set of a linked input port: no use under normal conditions
1053 // (value will be replaced by output value before activation and read)
1056 aString <<= (const char *)"texte";
1057 _nodeMap["Node_20"]->getInputPort("str")->put(&aString);
1058 // _nodeMap["Node_20"]->getInputPort("str")->edInit("texte");
1062 set<InputPort *> unitialized = _blocMap["Bloc_3"]->edGetSetOfUnitializedInputPort();
1063 DEBTRACE(unitialized.size());
1064 CPPUNIT_ASSERT( _blocMap["Bloc_3"]->edAreAllInputPortInitialized() );
1073 DEBTRACE("Python input port double");
1074 InputPort* inport=_nodeMap["Node_10"]->getInputPort("a");
1076 DEBTRACE("Initialize port with C++ double value");
1077 a = AtomAny::New(d);
1078 inport->edInit("Cpp",a);
1080 pyob=((InputPyPort*)inport)->getPyObj();
1081 DEBTRACE(pyob->ob_refcnt);
1082 CPPUNIT_ASSERT(PyFloat_AS_DOUBLE(pyob) == d);
1084 DEBTRACE("Initialize port with XML double value");
1085 inport->edInit("XML","<value><double>10.51</double></value>");
1086 pyob=((InputPyPort*)inport)->getPyObj();
1087 DEBTRACE(pyob->ob_refcnt);
1088 CPPUNIT_ASSERT(PyFloat_AS_DOUBLE(pyob) == d);
1090 DEBTRACE("Initialize port with XML int value");
1091 inport->edInit("XML","<value><int>10</int></value>");
1092 pyob=((InputPyPort*)inport)->getPyObj();
1093 DEBTRACE(pyob->ob_refcnt);
1094 CPPUNIT_ASSERT(PyFloat_AS_DOUBLE(pyob) == 10.);
1096 DEBTRACE("Initialize port with Python double value");
1097 PyGILState_STATE gstate = PyGILState_Ensure();
1098 inport->edInit("Python",PyFloat_FromDouble(d));
1099 PyGILState_Release(gstate);
1100 pyob=((InputPyPort*)inport)->getPyObj();
1101 DEBTRACE(pyob->ob_refcnt);
1102 CPPUNIT_ASSERT(PyFloat_AS_DOUBLE(pyob) == d);
1104 DEBTRACE("Python input port seq<double>");
1105 inport=_nodeMap["Node_14"]->getInputPort("li");
1106 DEBTRACE("Initialize port with XML seq<double> value");
1107 inport->edInit("XML","<value><array><data>\
1108 <value><double>1.5</double></value>\
1109 <value><double>2.4</double></value>\
1110 </data></array></value>");
1111 pyob=((InputPyPort*)inport)->getPyObj();
1112 DEBTRACE(pyob->ob_refcnt);
1114 DEBTRACE("Initialize port with XML seq<int> value");
1115 inport->edInit("XML","<value><array><data>\
1116 <value><int>15</int></value>\
1117 <value><int>24</int></value>\
1118 </data></array></value>");
1119 pyob=((InputPyPort*)inport)->getPyObj();
1120 DEBTRACE(pyob->ob_refcnt);
1122 DEBTRACE("CORBA input port int");
1123 inport=_nodeMap["Node_20"]->getInputPort("long");
1124 DEBTRACE("Initialize port with XML int value");
1125 inport->edInit("XML","<value><int>10</int></value>");
1126 any=((InputCorbaPort*)inport)->getAny();
1130 DEBTRACE("l = " << l);
1131 CPPUNIT_ASSERT(l == 10);
1133 DEBTRACE("CORBA input port double");
1134 inport=_nodeMap["Node_17"]->getInputPort("b");
1135 DEBTRACE("Initialize port with XML double value");
1136 inport->edInit("XML","<value><double>10.51</double></value>");
1137 any=((InputCorbaPort*)inport)->getAny();
1139 CPPUNIT_ASSERT_DOUBLES_EQUAL(10.51,d, 1e-12);
1141 DEBTRACE("CORBA input port seq<double>");
1142 inport=_nodeMap["Node_24"]->getInputPort("dblevec");
1143 DEBTRACE("Initialize port with XML seq<double> value");
1144 inport->edInit("XML","<value><array><data>\
1145 <value><double>1.5</double></value>\
1146 <value><double>2.4</double></value>\
1147 </data></array></value>");
1152 void RuntimeTest::manualExecuteNoThread()
1154 DEBTRACE(" --- execution Python Node_10" );
1155 ((ElementaryNode*)_nodeMap["Node_10"])->load();
1156 ((ElementaryNode*)_nodeMap["Node_10"])->execute();
1157 // CPPUNIT_ASSERT_DOUBLES_EQUAL(10.51, (ElementaryNode*)_nodeMap["Node_10"])
1158 DEBTRACE(" --- execution Python Node_11" );
1159 ((ElementaryNode*)_nodeMap["Node_11"])->load();
1160 ((ElementaryNode*)_nodeMap["Node_11"])->execute();
1162 DEBTRACE(" --- execution Python Node_12" );
1163 ((ElementaryNode*)_nodeMap["Node_12"])->load();
1164 ((ElementaryNode*)_nodeMap["Node_12"])->execute();
1166 DEBTRACE(" --- execution CORBA Node_16" );
1167 ((ElementaryNode*)_nodeMap["Node_16"])->load();
1168 ((ElementaryNode*)_nodeMap["Node_16"])->execute();
1170 DEBTRACE(" --- execution CORBA Node_17" );
1171 ((ElementaryNode*)_nodeMap["Node_17"])->load();
1172 ((ElementaryNode*)_nodeMap["Node_17"])->execute();
1174 DEBTRACE(" --- execution CORBA Node_18" );
1175 ((ElementaryNode*)_nodeMap["Node_18"])->load();
1176 ((ElementaryNode*)_nodeMap["Node_18"])->execute();
1178 DEBTRACE(" --- execution CORBA Node_19" );
1179 ((ElementaryNode*)_nodeMap["Node_19"])->load();
1180 ((ElementaryNode*)_nodeMap["Node_19"])->execute();
1182 DEBTRACE(" --- execution CORBA Node_20" );
1183 ((ElementaryNode*)_nodeMap["Node_20"])->load();
1184 ((ElementaryNode*)_nodeMap["Node_20"])->execute();
1186 DEBTRACE(" --- execution CORBA Node_21" );
1187 ((ElementaryNode*)_nodeMap["Node_21"])->load();
1188 ((ElementaryNode*)_nodeMap["Node_21"])->execute();
1190 DEBTRACE(" --- execution CORBA Node_29" );
1191 ((ElementaryNode*)_nodeMap["Node_29"])->load();
1192 ((ElementaryNode*)_nodeMap["Node_29"])->execute();
1194 DEBTRACE(" --- execution Python Node_13" );
1195 ((ElementaryNode*)_nodeMap["Node_13"])->load();
1196 ((ElementaryNode*)_nodeMap["Node_13"])->execute();
1198 DEBTRACE(" --- execution CORBA Node_22" );
1199 ((ElementaryNode*)_nodeMap["Node_22"])->load();
1200 ((ElementaryNode*)_nodeMap["Node_22"])->execute();
1202 DEBTRACE(" --- execution CORBA Node_23" );
1203 ((ElementaryNode*)_nodeMap["Node_23"])->load();
1204 ((ElementaryNode*)_nodeMap["Node_23"])->execute();
1206 DEBTRACE(" --- execution CORBA Node_24" );
1207 ((ElementaryNode*)_nodeMap["Node_24"])->load();
1208 ((ElementaryNode*)_nodeMap["Node_24"])->execute();
1210 DEBTRACE(" --- execution CORBA Node_27" );
1211 ((ElementaryNode*)_nodeMap["Node_27"])->load();
1212 ((ElementaryNode*)_nodeMap["Node_27"])->execute();
1214 DEBTRACE(" --- execution CORBA Node_28" );
1215 ((ElementaryNode*)_nodeMap["Node_28"])->load();
1216 ((ElementaryNode*)_nodeMap["Node_28"])->execute();
1218 DEBTRACE(" --- execution CORBA Node_30" );
1219 ((ElementaryNode*)_nodeMap["Node_30"])->load();
1220 ((ElementaryNode*)_nodeMap["Node_30"])->execute();
1222 DEBTRACE(" --- execution CORBA Node_32" );
1223 ((ElementaryNode*)_nodeMap["Node_32"])->load();
1224 ((ElementaryNode*)_nodeMap["Node_32"])->execute();
1226 DEBTRACE(" --- execution CORBA Node_26" );
1227 ((ElementaryNode*)_nodeMap["Node_26"])->load();
1228 ((ElementaryNode*)_nodeMap["Node_26"])->execute();
1230 DEBTRACE(" --- execution CORBA Node_31" );
1231 ((ElementaryNode*)_nodeMap["Node_31"])->load();
1232 ((ElementaryNode*)_nodeMap["Node_31"])->execute();
1234 DEBTRACE(" --- execution Python Node_14" );
1235 ((ElementaryNode*)_nodeMap["Node_14"])->load();
1236 ((ElementaryNode*)_nodeMap["Node_14"])->execute();
1238 DEBTRACE(" --- execution Python Node_15" );
1239 ((ElementaryNode*)_nodeMap["Node_15"])->load();
1240 ((ElementaryNode*)_nodeMap["Node_15"])->execute();
1242 std::cerr << __LINE__ << std::endl;
1243 DEBTRACE(" --- execution XML Node_36" );
1244 ((ElementaryNode*)_nodeMap["Node_36"])->load();
1245 ((ElementaryNode*)_nodeMap["Node_36"])->execute();
1247 DEBTRACE(" --- execution CORBA Node_33" );
1248 ((ElementaryNode*)_nodeMap["Node_33"])->load();
1249 ((ElementaryNode*)_nodeMap["Node_33"])->execute();
1251 DEBTRACE(" --- execution CORBA Node_34" );
1252 ((ElementaryNode*)_nodeMap["Node_34"])->load();
1253 ((ElementaryNode*)_nodeMap["Node_34"])->execute();
1255 DEBTRACE(" --- execution CORBA Node_35" );
1256 ((ElementaryNode*)_nodeMap["Node_35"])->load();
1257 ((ElementaryNode*)_nodeMap["Node_35"])->execute();
1259 DEBTRACE(" --- end of execution" );
1263 void RuntimeTest::manualGetOutputs()
1268 PyObject *ob=((OutputPyPort*)_nodeMap["Node_11"]->getOutputPort("c"))->get();
1269 DEBTRACE("ob refcnt: " << ob->ob_refcnt);
1270 std::cerr << "Output port Node_11.c: ";
1271 PyGILState_STATE gstate = PyGILState_Ensure();
1272 PyObject_Print(ob,stderr,Py_PRINT_RAW);
1273 PyGILState_Release(gstate);
1274 std::cerr << std::endl;
1276 // DEBTRACE("a: " << &a);
1277 // DEBTRACE("a.value(): " << a.value());
1279 x= ((InputCorbaPort*)_nodeMap["Node_16"]->getInputPort("a"))->getAny();
1280 DEBTRACE("CORBA Node_16 input a any: " << x);
1282 DEBTRACE("CORBA Node_16 input a double: " << l);
1284 *((InputCorbaPort*)_nodeMap["Node_17"]->getInputPort("b"))->getAny() >>= l;
1285 DEBTRACE("CORBA Node_17 input b double: " << l);
1287 *((InputCorbaPort*)_nodeMap["Node_18"]->getInputPort("b"))->getAny() >>= l;
1288 DEBTRACE("CORBA Node_18 input a double: " << l);
1290 *((OutputCorbaPort*)_nodeMap["Node_16"]->getOutputPort("c"))->getAny() >>= l;
1291 DEBTRACE("CORBA Node_16 output c double: " << l);
1293 *((OutputCorbaPort*)_nodeMap["Node_17"]->getOutputPort("c"))->getAny() >>= l;
1294 DEBTRACE("CORBA Node_17 output c double: " << l);
1296 *((OutputCorbaPort*)_nodeMap["Node_18"]->getOutputPort("c"))->getAny() >>= l;
1297 DEBTRACE("CORBA Node_18 output c double: " << l);
1299 DEBTRACE(" --- fini" );
1302 void RuntimeTest::createCppNodes()
1305 string s = "Node_Cpp";
1306 ElementaryNode* node = _myRuntime->createCompoNode("Cpp",s);
1308 InputPort *i1 = node->edAddInputPort("id1", _tc_double);
1309 InputPort *i2 = node->edAddInputPort("ii2", _tc_int);
1311 OutputPort *o3 = node->edAddOutputPort("os3", _tc_string);
1313 CPPUNIT_ASSERT_EQUAL(node->getImplementation(),string("Cpp"));
1314 CPPUNIT_ASSERT_EQUAL(node->getNumberOfInputPorts(),2);
1315 CPPUNIT_ASSERT_EQUAL(node->getNumberOfOutputPorts(),1);
1316 CPPUNIT_ASSERT_EQUAL(node->getInPortName(i1),string("id1"));
1317 CPPUNIT_ASSERT_EQUAL(node->getOutPortName(o3),string("os3"));
1319 CPPUNIT_ASSERT_EQUAL(node->getInputPort("id1"),i1);
1320 CPPUNIT_ASSERT_EQUAL(node->getOutputPort("os3"),o3);
1325 void RuntimeTest::convertPorts()
1327 const char *type[] = { "Cpp", "CORBA", "Python", "XML" };
1328 int itype, jtype, ntypes = sizeof(type)/sizeof(const char *);
1330 string s0 = "Node_";
1336 for (itype=0; itype<ntypes-1; itype++)
1338 string s = s0 + type[itype];
1341 DEBTRACE("Node " << type[itype] << " creation");
1342 ElementaryNode* node;
1346 node = _myRuntime->createRefNode(type[itype],s);
1349 node = _myRuntime->createScriptNode(type[itype], s);
1352 node = _myRuntime->createRefNode("xmlsh",s);
1355 node = _myRuntime->createCompoNode(type[itype], s);
1358 InputPort *inport = node->edAddInputPort("id1", _tc_double);
1359 CPPUNIT_ASSERT(NULL != node);
1360 for (jtype=0; jtype < ntypes; jtype++)
1362 double d0= itype * 10 + jtype, d1;
1363 InputPort* pwrap=_myRuntime->adapt(inport, type[jtype], _tc_double);
1370 v = vAny = AtomAny::New(d0);
1374 cAny <<= (CORBA::Double) d0;
1377 v = pAny = PyFloat_FromDouble(d0);
1382 os << "<value><double>" << d0 << "</double></value>";
1392 if ((itype == 2) && (jtype == 2))
1394 std::cerr << "s = " << s << endl;
1397 DEBTRACE("Put a " << type[jtype] << " double (" << d0 << ") in " << s);
1400 PyGILState_STATE gstate = PyGILState_Ensure();
1402 PyGILState_Release(gstate);
1413 Any * a=((InputCppPort*)inport)->getCppObj();
1414 CPPUNIT_ASSERT(a->getType()->isA(_tc_double));
1415 d1 = a->getDoubleValue();
1420 CORBA::Any * a = ((InputCorbaPort*)inport)->getAny();
1421 CPPUNIT_ASSERT(a->type()->equal(CORBA::_tc_double));
1429 PyObject *a = ((InputPyPort*)inport)->getPyObj();
1430 CPPUNIT_ASSERT(PyFloat_Check(a));
1431 d1 = PyFloat_AsDouble(a);
1436 const char *a = ((InputXmlPort*)inport)->getXml();
1437 const char *a1, *a2, *a3, *a_end;
1438 a_end = a + strlen(a) - 1;
1439 while (isspace(*a_end)) a_end--;
1441 a2 = a + strlen("<value><double>");
1442 a3 = a_end - strlen("</double></value>") + 1;
1443 CPPUNIT_ASSERT(!strncmp(a1, "<value><double>", strlen("<value><double>")));
1444 CPPUNIT_ASSERT(!strncmp(a3, "</double></value>", strlen("</double></value>")));
1446 d1 = strtod(a2, &err);
1447 CPPUNIT_ASSERT(err == a3);
1452 CPPUNIT_ASSERT_DOUBLES_EQUAL(d0, d1, 1e-12);
1466 if (pwrap != inport) delete pwrap;
1472 void myTestRun(int nIn, int nOut, Any **In, Any **Out) throw (YACS::Exception)
1475 cerr << "myTestRun nIn = " << nIn << endl;
1476 cerr << "myTestRun nOut = " << nOut << endl;
1478 x = In[0]->getDoubleValue();
1483 Out[0] = AtomAny::New(y);
1487 throw YACS::Exception("myTestRun : input must be a positive or null real");
1492 void RuntimeTest::executeCppNode()
1494 cerr << endl << endl;
1499 DEBTRACE("execute a CppNode with an internal C++ implementation")
1500 ServiceNode * node = _myRuntime->createCompoNode("Cpp", "test");
1501 ((CppNode *) node)->setFunc(myTestRun);
1503 InputPort *in = node->edAddInputPort("in", _tc_double);
1504 OutputPort *out = node->edAddOutputPort("out", _tc_double);
1508 v = AtomAny::New(dv);
1509 in->edInit("Cpp",v);
1513 w = ((OutputCppPort *) out)->get();
1514 dw = w->getDoubleValue();
1516 cerr << "sqrt(" << dv << ") = " << dw << endl;
1517 CPPUNIT_ASSERT_DOUBLES_EQUAL(dw, sqrt(dv), 1e-12);
1519 u = AtomAny::New((double) -3.5);
1520 in->edInit("Cpp",u);
1521 CPPUNIT_ASSERT_THROW(node->execute(), YACS::Exception);
1528 DEBTRACE("execute a CppNode with an external C++ implementation (in a dynamic library)");
1530 node = _myRuntime->createCompoNode("Cpp", "test");
1531 CppComponent * C = new CppComponent("TestComponent");
1532 node->setComponent(C);
1534 node->setMethod("f");
1536 in = node->edAddInputPort("in", _tc_double);
1537 out = node->edAddOutputPort("out", _tc_double);
1541 v = AtomAny::New(dv);
1542 in->edInit("Cpp",v);
1546 w = ((OutputCppPort *) out)->get();
1547 dw = w->getDoubleValue();
1549 cerr << "sqrt(" << dv << ") = " << dw << endl;
1550 CPPUNIT_ASSERT_DOUBLES_EQUAL(dw, sqrt(dv), 1e-12);
1552 u = AtomAny::New((double) -3.5);
1553 in->edInit("Cpp",u);
1554 CPPUNIT_ASSERT_THROW(node->execute(), YACS::Exception);
1563 void RuntimeTest::createGraphWithCppNodes()
1565 ElementaryNode * n1, * n2;
1566 InputPort *in1, *in2;
1567 OutputPort *out1, *out2;
1569 n1 = _myRuntime->createCompoNode(CppNode::KIND, "test1");
1570 n2 = _myRuntime->createScriptNode(PythonNode::KIND, "test2");
1572 CppComponent *C = new CppComponent("TestComponent");
1573 ((CppNode *) n1)->setComponent(C);
1575 ((CppNode *) n1)->setMethod("f");
1576 in1 = n1->edAddInputPort("i", _tc_double);
1577 out1 = n1->edAddOutputPort("o", _tc_double);
1579 ((InlineNode*) n2)->setScript("a=a+1\n");
1580 in2 = n2->edAddInputPort("a", _tc_double);
1581 out2 = n2->edAddOutputPort("a", _tc_double);
1583 Bloc * loopBody = _myRuntime->createBloc("LoopBody");
1584 loopBody->edAddChild(n1);
1585 loopBody->edAddChild(n2);
1586 loopBody->edAddLink(out1, in2);
1587 loopBody->edAddLink(out2, in1);
1589 ForLoop *loop=_myRuntime->createForLoop("Loop");
1590 loop->edSetNode(loopBody);
1591 InputPort *iNbTimes=loop->edGetNbOfTimesInputPort();
1592 iNbTimes->edInit(5);
1594 Bloc * graph = _myRuntime->createBloc("graph");
1595 graph->edAddChild(loop);
1597 DEBTRACE("n1->getInputPort(\"in\") = " << n1->getInputPort("i")->getName())
1605 DEBTRACE(out2->dump());
1610 void RuntimeTest::classTeardown()
1612 if (endTests) return;
1616 delete _blocMap["Bloc_3"];
1617 delete _blocMap["Bloc_2"];
1618 delete _nodeMap["Node_4"];
1619 delete _nodeMap["Node_5"];
1620 delete _nodeMap["Node_6"];
1621 delete _nodeMap["Node_7"];
1622 delete _nodeMap["Node_8"];
1623 delete _nodeMap["Node_9"];
1625 _tc_seqC->decrRef();
1627 list<TypeCodeObjref *>::iterator i;
1628 for (i=_ltc.begin(); i != _ltc.end(); i++)
1631 _tc_seqseqobj->decrRef();
1632 _tc_seqobj->decrRef();
1636 _tc_seqseqdble->decrRef();
1637 _tc_seqdble->decrRef();
1638 _tc_seqstr->decrRef();
1639 _tc_seqlong->decrRef();
1640 _tc_string->decrRef();