]> SALOME platform Git repositories - modules/yacs.git/blob - src/runtime/Test/runtimeTest.cxx
Salome HOME
Before virtualization of SalomeContainerTools
[modules/yacs.git] / src / runtime / Test / runtimeTest.cxx
1 // Copyright (C) 2006-2019  CEA/DEN, EDF R&D
2 //
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.
7 //
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.
12 //
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
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 // --- include from engine first, to avoid redifinition warning _POSIX_C_SOURCE
21 //
22 #include "TypeConversions.hxx"
23 #include "Bloc.hxx"
24 #include "ElementaryNode.hxx"
25 #include "Loop.hxx"
26 #include "ForLoop.hxx"
27 #include "Switch.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"
39
40 #include "runtimeTest.hxx"
41
42 #include <iostream>
43 #include <sstream>
44 #include <string>
45 #include <list>
46 #include <vector>
47 #include <map>
48 #include <cctype>
49 #include <cstdlib>
50
51 //#define _DEVDEBUG_
52 #include "YacsTrace.hxx"
53
54 using namespace YACS::ENGINE;
55 using namespace YACS;
56 using namespace std;
57
58 // --- init typecodes
59
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);
72
73 list<TypeCodeObjref *> RuntimeTest::_ltc;
74 TypeCode *RuntimeTest::_tc_C;
75 TypeCode *RuntimeTest::_tc_seqC;
76
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;
83
84 void RuntimeTest::setUp()
85 {
86   if (_ltc.size() == 0)
87     {
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);
91     }
92 }
93
94
95 #define cRef(x) cerr << "_tc" << #x << " : " << _tc ## x->getRefCnt() << endl
96
97 void RuntimeTest::tearDown()
98 {
99 }
100
101
102 void RuntimeTest::initRuntimeTypeCode()
103 {
104   // --- init runtime
105   std::cerr << std::endl;
106   RuntimeSALOME::setRuntime();
107   _myRuntime = getRuntime();
108   
109   // --- init typecodes
110   
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));
120 }
121
122 void RuntimeTest::createPythonNodes()
123 {
124   // --- Nodes 0 a 4 : Python
125
126   for (int i=0; i<5; i++)
127     {
128       ostringstream ss;
129       ss << "Node_" << _inode++;
130       string s = ss.str();
131       ElementaryNode* node = _myRuntime->createScriptNode("",s);
132       _nodeMap[s] = node;
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);
144
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);
163     }
164 }
165
166
167 void RuntimeTest::createCORBANodes()
168 {
169   // --- Nodes 5 a 9 : CORBA
170
171   for (int i=5; i<10; i++)
172     {
173       ostringstream ss;
174       ss << "Node_" << _inode++;
175       string s = ss.str();
176       ElementaryNode* node = _myRuntime->createRefNode("",s);
177       _nodeMap[s] = node;
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);
189
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);
208     }
209 }
210
211
212 void RuntimeTest::createBloc()
213 {
214   DEBTRACE(" --- create bloc, add two nodes, check constituants" );
215
216   // --- Bloc_0 with Node_0 and Node_1
217   {
218     ostringstream ss;
219     ss << "Bloc_" << _ibloc++;
220     string s = ss.str();
221     Bloc* bloc = new Bloc(s);
222     _nodeMap[s] = bloc;
223     _blocMap[s] = bloc;
224     bloc->edAddChild(_nodeMap["Node_0"]);
225     bloc->edAddChild(_nodeMap["Node_1"]);
226     {
227       list<ElementaryNode *> setelem = bloc->getRecursiveConstituents();
228       CPPUNIT_ASSERT(setelem.size() == 2);
229     }
230   }
231
232   // --- Bloc_1 with Node_2
233   {
234     ostringstream ss;
235     ss << "Bloc_" << _ibloc++;
236     string s = ss.str();
237     Bloc* bloc = new Bloc(s);
238     _nodeMap[s] = bloc;
239     _blocMap[s] = bloc;
240     bloc->edAddChild(_nodeMap["Node_2"]);
241   }
242
243   DEBTRACE(" --- add a node already used in the bloc does nothing (return false)" );
244   CPPUNIT_ASSERT( ! _blocMap["Bloc_0"]->edAddChild(_nodeMap["Node_1"]));
245
246   DEBTRACE(" --- add a node already used elsewhere raises exception " );
247   CPPUNIT_ASSERT_THROW(_blocMap["Bloc_1"]->edAddChild(_nodeMap["Node_1"]),
248                        YACS::Exception);
249 }
250
251
252 void RuntimeTest::createRecursiveBlocs()
253 {
254   DEBTRACE(" --- recursive blocs, check constituants" );
255
256   // --- Bloc_2 with Bloc_0, Bloc_1 and Node_3
257   {
258     ostringstream ss;
259     ss << "Bloc_" << _ibloc++;
260     string s = ss.str();
261     Bloc* bloc = new Bloc(s);
262     _nodeMap[s] = bloc;
263     _blocMap[s] = bloc;
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
267   }
268
269   {
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++)
273       {
274         DEBTRACE("     elem name = " << (*it)->getName());
275       }
276   }
277 }
278
279
280 void RuntimeTest::createDataLinks()
281 {
282   DEBTRACE(" --- create and delete data links" );
283
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);
289
290   _blocMap["Bloc_0"]->edAddLink(_nodeMap["Node_0"]->getOutputPort("oi2"),
291                                 _nodeMap["Node_1"]->getInputPort("ii2"));
292   CPPUNIT_ASSERT(_blocMap["Bloc_0"]->getNumberOfInputPorts() == 22);
293
294   _blocMap["Bloc_0"]->edRemoveLink(_nodeMap["Node_0"]->getOutputPort("oi2"),
295                                    _nodeMap["Node_1"]->getInputPort("ii2"));
296   CPPUNIT_ASSERT(_blocMap["Bloc_0"]->getNumberOfInputPorts() == 22);
297 }
298
299
300 void RuntimeTest::createPythonNodesWithScript()
301 {
302   DEBTRACE(" --- create python nodes with scripts" );
303
304   // --- Node 10 : Python
305
306   {
307     ostringstream ss;
308     ss << "Node_" << _inode++;
309     string s = ss.str();
310     ElementaryNode* node = _myRuntime->createScriptNode("",s);
311     _nodeMap[s] = node;
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);
318   }
319  
320   // --- Node 11 : Python
321
322   {
323     ostringstream ss;
324     ss << "Node_" << _inode++;
325     string s = ss.str();
326     ElementaryNode* node = _myRuntime->createScriptNode("",s);
327     _nodeMap[s] = node;
328     ((InlineNode*) node)->setScript("a=b+1\n"
329                                      "c=2*a\n"
330                                      "i=10\n"
331                                      "s='aaaaaaa'\n"
332                                      "seqdble=[1.5,2.4]\n"
333                                      "lngvec=[1,2]\n"
334                                      "dblevecvec=[[1.5,2.4],[6.7,7.8]]\n"
335                                      );
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);
343   }
344
345   // --- Node 12 : Python
346
347   {
348     ostringstream ss;
349     ss << "Node_" << _inode++;
350     string s = ss.str();
351     ElementaryNode* node = _myRuntime->createScriptNode("",s);
352     _nodeMap[s] = node;
353     ((InlineNode*) node)->setScript("a=dble+1\n"
354                                      "dble=2*a\n"
355                                      );
356     InputPort  *i1  = node->edAddInputPort("dble",  _tc_double);
357     OutputPort *o1  = node->edAddOutputPort("dble", _tc_double);
358   }
359  
360   // --- Node 13 : Python
361
362   {
363     ostringstream ss;
364     ss << "Node_" << _inode++;
365     string s = ss.str();
366     ElementaryNode* node = _myRuntime->createScriptNode("",s);
367     _nodeMap[s] = node;
368     ((InlineNode*) node)->setScript("print('node 13')\n"
369                                      "import eo\n"
370                                      "print(ob)\n"
371                                      "o=ob._narrow(eo.Obj)\n"
372                                      "print(o)\n"
373                                      "print(o.echoLong(13))\n"
374                                      "a=dble+1\n"
375                                      "dble=2*a\n"
376                                      "print(lng)\n"
377                                      "print('++++++++',s,'+++++++++++++')\n"
378                                      "ob=o\n"
379                                      "seqstr=['aaa','bbb']\n"
380                                      "seqobj=[o,o,o,o]\n"
381                                      "seqseqobj=[[o,o],[o,o]]\n"
382                                      );
383
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);
406   }
407  
408   // --- Node 14 : Python
409
410   {
411     ostringstream ss;
412     ss << "Node_" << _inode++;
413     string s = ss.str();
414     ElementaryNode* node = _myRuntime->createScriptNode("",s);
415     _nodeMap[s] = node;
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"
422                                      "li=2*li\n"
423                                      );
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);
440   }
441  
442   // --- Node 15 : Python
443
444   {
445     ostringstream ss;
446     ss << "Node_" << _inode++;
447     string s = ss.str();
448     ElementaryNode* node = _myRuntime->createScriptNode("",s);
449     _nodeMap[s] = node;
450     ((InlineNode*) node)->setScript("print(li)\n"
451                                      "li=[2*e for e in li]\n"
452                                      "print('obj=',obj)\n"
453                                      "print(li)\n"
454                                      "print(lngvec)\n"
455                                      "print(dblevec)\n"
456                                      );
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);
465   }
466 }
467
468 void RuntimeTest::createCORBANodesWithMethod()
469 {
470   DEBTRACE(" --- create CORBA nodes" );
471
472   // --- Node 16 : CORBA
473
474   {
475     ostringstream ss;
476     ss << "Node_" << _inode++;
477     string s = ss.str();
478     ElementaryNode* node = _myRuntime->createRefNode("",s);
479     _nodeMap[s] = node;
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);
489   }
490  
491   // --- Node 17 - 18 : CORBA
492
493   for (int i =0; i <2; i++)
494     {
495       ostringstream ss;
496       ss << "Node_" << _inode++;
497       string s = ss.str();
498       ElementaryNode* node = _myRuntime->createRefNode("",s);
499       _nodeMap[s] = node;
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);
504     }
505
506   // --- Node 19 : CORBA
507
508   {
509     ostringstream ss;
510     ss << "Node_" << _inode++;
511     string s = ss.str();
512     ElementaryNode* node = _myRuntime->createRefNode("",s);
513     _nodeMap[s] = node;
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);
520   }
521  
522   // --- Node 20, 21, 22 : CORBA
523
524   for (int i =0; i <3; i++)
525     {
526       ostringstream ss;
527       ss << "Node_" << _inode++;
528       string s = ss.str();
529       ElementaryNode* node = _myRuntime->createRefNode("",s);
530       _nodeMap[s] = node;
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);
545     }
546  
547   // --- Node 23 a 26 : CORBA
548
549   for (int i =0; i <4; i++)
550     {
551       ostringstream ss;
552       ss << "Node_" << _inode++;
553       string s = ss.str();
554       ElementaryNode* node = _myRuntime->createRefNode("",s);
555       _nodeMap[s] = node;
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);
562     }
563  
564   // --- Node 27 : CORBA
565
566   {
567     ostringstream ss;
568     ss << "Node_" << _inode++;
569     string s = ss.str();
570     ElementaryNode* node = _myRuntime->createRefNode("",s);
571     _nodeMap[s] = node;
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);
578   }
579
580   // --- Node 28 : CORBA
581
582   {
583     ostringstream ss;
584     ss << "Node_" << _inode++;
585     string s = ss.str();
586     ElementaryNode* node = _myRuntime->createRefNode("",s);
587     _nodeMap[s] = node;
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);
594   }
595
596   // --- Node 29 : CORBA
597
598   {
599     ostringstream ss;
600     ss << "Node_" << _inode++;
601     string s = ss.str();
602     ElementaryNode* node = _myRuntime->createRefNode("",s);
603     _nodeMap[s] = node;
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);
610   }
611  
612   // --- Node 30 : CORBA
613
614   {
615     ostringstream ss;
616     ss << "Node_" << _inode++;
617     string s = ss.str();
618     ElementaryNode* node = _myRuntime->createRefNode("",s);
619     _nodeMap[s] = node;
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);
626   }
627  
628   // --- Node 31 : CORBA
629
630   {
631     ostringstream ss;
632     ss << "Node_" << _inode++;
633     string s = ss.str();
634     ElementaryNode* node = _myRuntime->createRefNode("",s);
635     _nodeMap[s] = node;
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);
642   }
643
644   // --- Node 32 : CORBA
645
646   {
647     ostringstream ss;
648     ss << "Node_" << _inode++;
649     string s = ss.str();
650     ElementaryNode* node = _myRuntime->createRefNode("",s);
651     _nodeMap[s] = node;
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);
656   }
657
658   // --- Node 33 : CORBA
659
660   {
661     ostringstream ss;
662     ss << "Node_" << _inode++;
663     string s = ss.str();
664     ElementaryNode* node = _myRuntime->createRefNode("",s);
665     _nodeMap[s] = node;
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);
670   }
671
672   // --- Node 34 : CORBA
673
674   {
675     ostringstream ss;
676     ss << "Node_" << _inode++;
677     string s = ss.str();
678     ElementaryNode* node = _myRuntime->createRefNode("",s);
679     _nodeMap[s] = node;
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);
684   }
685
686   // --- Node 35 : CORBA
687
688   {
689     ostringstream ss;
690     ss << "Node_" << _inode++;
691     string s = ss.str();
692     ElementaryNode* node = _myRuntime->createRefNode("",s);
693     _nodeMap[s] = node;
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);
698   }
699 }
700
701
702 void RuntimeTest::createXMLNodes()
703 {
704   DEBTRACE(" --- create XML nodes" );
705
706   // --- Node 36 : XML
707
708   {
709     ostringstream ss;
710     ss << "Node_" << _inode++;
711     string s = ss.str();
712     ElementaryNode* node = _myRuntime->createRefNode("xmlsh",s);
713     _nodeMap[s] = node;
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);
725   }
726 }
727
728
729 void RuntimeTest::createBloc2()
730 {
731   DEBTRACE(" --- create Bloc with all nodes" );
732   
733   // --- Bloc_3 with Node_10 and following
734
735   {
736     ostringstream ss;
737     ss << "Bloc_" << _ibloc++;
738     string s = ss.str();
739     Bloc* bloc = new Bloc(s);
740     _nodeMap[s] = bloc;
741     _blocMap[s] = bloc;
742     for (int i=10; i<_inode; i++)
743       {
744         ostringstream ssn;
745         ssn << "Node_" << i;
746         string sn = ssn.str();
747         cerr << sn << endl;
748         bloc->edAddChild(_nodeMap[sn]);
749       }
750     {
751       list<ElementaryNode *> setelem = bloc->getRecursiveConstituents();
752       CPPUNIT_ASSERT(setelem.size() == _inode - 10);
753     }
754   }
755   set<InputPort *> unitialized =  _blocMap["Bloc_3"]->edGetSetOfUnitializedInputPort();
756   DEBTRACE(unitialized.size());
757   CPPUNIT_ASSERT(! _blocMap["Bloc_3"]->edAreAllInputPortInitialized() );
758 }
759
760
761 void RuntimeTest::createDataLinksPythonPython()
762 {
763   DEBTRACE(" --- create data links, python to python" );
764
765
766   _blocMap["Bloc_3"]->edAddLink(_nodeMap["Node_10"]->getOutputPort("a"),
767                                 _nodeMap["Node_11"]->getInputPort("b"));
768
769
770   _blocMap["Bloc_3"]->edAddLink(_nodeMap["Node_10"]->getOutputPort("a"),
771                                 _nodeMap["Node_12"]->getInputPort("dble"));
772
773   // --- Python sequence<double> -> Python sequence<double>
774   _blocMap["Bloc_3"]->edAddLink(_nodeMap["Node_14"]->getOutputPort("li"),
775                                 _nodeMap["Node_15"]->getInputPort("li"));
776
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"));
780
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);
785
786   CPPUNIT_ASSERT_THROW(_blocMap["Bloc_3"]->edAddLink(_nodeMap["Node_11"]->getOutputPort("s"),
787                                                      _nodeMap["Node_12"]->getInputPort("dble")),
788                        YACS::ENGINE::ConversionException);
789
790   CPPUNIT_ASSERT_THROW(_blocMap["Bloc_3"]->edAddLink(_nodeMap["Node_11"]->getOutputPort("seqdble"),
791                                                      _nodeMap["Node_12"]->getInputPort("dble")),
792                        YACS::ENGINE::ConversionException);
793 }
794
795
796 void RuntimeTest::createDataLinksPythonCORBA()
797 {
798   DEBTRACE(" --- create data links, python to CORBA" );
799
800   // --- double->double
801   _blocMap["Bloc_3"]->edAddLink(_nodeMap["Node_11"]->getOutputPort("c"),
802                                 _nodeMap["Node_16"]->getInputPort("a"));
803
804   // --- int->int
805   _blocMap["Bloc_3"]->edAddLink(_nodeMap["Node_11"]->getOutputPort("i"),
806                                 _nodeMap["Node_19"]->getInputPort("long"));
807
808   // --- str->str
809   _blocMap["Bloc_3"]->edAddLink(_nodeMap["Node_11"]->getOutputPort("s"),
810                                 _nodeMap["Node_20"]->getInputPort("str"));
811   cerr << "##### 3" << endl;
812
813   // --- seq<long> -> seq<double>
814   _blocMap["Bloc_3"]->edAddLink(_nodeMap["Node_11"]->getOutputPort("lngvec"),
815                                 _nodeMap["Node_23"]->getInputPort("dblevec"));
816
817   // --- seq<long> -> seq<long>
818   _blocMap["Bloc_3"]->edAddLink(_nodeMap["Node_11"]->getOutputPort("lngvec"),
819                                 _nodeMap["Node_31"]->getInputPort("lngvec"));
820
821   _blocMap["Bloc_3"]->edAddLink(_nodeMap["Node_13"]->getOutputPort("ob"),
822                                 _nodeMap["Node_22"]->getInputPort("obj"));
823
824   _blocMap["Bloc_3"]->edAddLink(_nodeMap["Node_11"]->getOutputPort("seqdble"),
825                                 _nodeMap["Node_26"]->getInputPort("dblevec"));
826
827   _blocMap["Bloc_3"]->edAddLink(_nodeMap["Node_13"]->getOutputPort("seqstr"),
828                                 _nodeMap["Node_27"]->getInputPort("strvec"));
829
830   _blocMap["Bloc_3"]->edAddLink(_nodeMap["Node_13"]->getOutputPort("seqobj"),
831                                 _nodeMap["Node_28"]->getInputPort("objvec"));
832
833   _blocMap["Bloc_3"]->edAddLink(_nodeMap["Node_11"]->getOutputPort("dblevecvec"),
834                                 _nodeMap["Node_29"]->getInputPort("dblevecvec"));
835
836   _blocMap["Bloc_3"]->edAddLink(_nodeMap["Node_13"]->getOutputPort("seqseqobj"),
837                                 _nodeMap["Node_30"]->getInputPort("objvecvec"));
838
839   CPPUNIT_ASSERT_THROW(_blocMap["Bloc_3"]->edAddLink(_nodeMap["Node_11"]->getOutputPort("seqdble"),
840                                                      _nodeMap["Node_27"]->getInputPort("strvec")),
841                        YACS::ENGINE::ConversionException);
842
843   CPPUNIT_ASSERT_THROW(_blocMap["Bloc_3"]->edAddLink(_nodeMap["Node_13"]->getOutputPort("ob"),
844                                                      _nodeMap["Node_22"]->getInputPort("str")),
845                        YACS::ENGINE::ConversionException);
846
847   CPPUNIT_ASSERT_THROW(_blocMap["Bloc_3"]->edAddLink(_nodeMap["Node_13"]->getOutputPort("dble"),
848                                                      _nodeMap["Node_22"]->getInputPort("str")),
849                        YACS::ENGINE::ConversionException);
850
851   CPPUNIT_ASSERT_THROW(_blocMap["Bloc_3"]->edAddLink(_nodeMap["Node_13"]->getOutputPort("lng"),
852                                                      _nodeMap["Node_22"]->getInputPort("str")),
853                        YACS::ENGINE::ConversionException);
854
855   CPPUNIT_ASSERT_THROW(_blocMap["Bloc_3"]->edAddLink(_nodeMap["Node_13"]->getOutputPort("dble"),
856                                                      _nodeMap["Node_22"]->getInputPort("long")),
857                        YACS::ENGINE::ConversionException);
858
859   CPPUNIT_ASSERT_THROW(_blocMap["Bloc_3"]->edAddLink(_nodeMap["Node_13"]->getOutputPort("dble"),
860                                                      _nodeMap["Node_24"]->getInputPort("dblevec")),
861                        YACS::ENGINE::ConversionException);
862
863   CPPUNIT_ASSERT_THROW(_blocMap["Bloc_3"]->edAddLink(_nodeMap["Node_11"]->getOutputPort("dblevecvec"),
864                                                      _nodeMap["Node_24"]->getInputPort("dblevec")),
865                        YACS::ENGINE::ConversionException);
866
867   CPPUNIT_ASSERT_THROW(_blocMap["Bloc_3"]->edAddLink(_nodeMap["Node_13"]->getOutputPort("seqstr"),
868                                                      _nodeMap["Node_24"]->getInputPort("dblevec")),
869                        YACS::ENGINE::ConversionException);
870 }
871
872
873 void RuntimeTest::createDataLinksCORBACORBA()
874 {
875   DEBTRACE(" --- create data links, CORBA to CORBA" );
876
877   // double->double
878   _blocMap["Bloc_3"]->edAddLink(_nodeMap["Node_16"]->getOutputPort("c"),
879                                 _nodeMap["Node_17"]->getInputPort("b"));
880
881   // double->double
882   _blocMap["Bloc_3"]->edAddLink(_nodeMap["Node_16"]->getOutputPort("c"),
883                                 _nodeMap["Node_18"]->getInputPort("b"));
884
885   CPPUNIT_ASSERT_THROW(_blocMap["Bloc_3"]->edAddLink(_nodeMap["Node_19"]->getOutputPort("obj"),
886                                                      _nodeMap["Node_21"]->getInputPort("double")),
887                        YACS::ENGINE::ConversionException);
888
889   CPPUNIT_ASSERT_THROW(_blocMap["Bloc_3"]->edAddLink(_nodeMap["Node_23"]->getOutputPort("dblevec"),
890                                                      _nodeMap["Node_31"]->getInputPort("lngvec")),
891                        YACS::ENGINE::ConversionException);
892
893   CPPUNIT_ASSERT_THROW(_blocMap["Bloc_3"]->edAddLink(_nodeMap["Node_20"]->getOutputPort("str"),
894                                                      _nodeMap["Node_27"]->getInputPort("strvec")),
895                        YACS::ENGINE::ConversionException);
896
897   _blocMap["Bloc_3"]->edAddLink(_nodeMap["Node_19"]->getOutputPort("obj"),
898                                 _nodeMap["Node_20"]->getInputPort("obj"));
899
900   _blocMap["Bloc_3"]->edAddLink(_nodeMap["Node_18"]->getOutputPort("c"),
901                                 _nodeMap["Node_20"]->getInputPort("double"));
902
903   _blocMap["Bloc_3"]->edAddLink(_nodeMap["Node_20"]->getOutputPort("long"),
904                                 _nodeMap["Node_21"]->getInputPort("double"));
905
906   _blocMap["Bloc_3"]->edAddLink(_nodeMap["Node_20"]->getOutputPort("long"),
907                                 _nodeMap["Node_21"]->getInputPort("long"));
908
909   _blocMap["Bloc_3"]->edAddLink(_nodeMap["Node_20"]->getOutputPort("str"),
910                                 _nodeMap["Node_21"]->getInputPort("str"));
911
912   _blocMap["Bloc_3"]->edAddLink(_nodeMap["Node_20"]->getOutputPort("obj"),
913                                 _nodeMap["Node_21"]->getInputPort("obj"));
914
915   // Corba sequence<double> -> Corba sequence<double>
916   _blocMap["Bloc_3"]->edAddLink(_nodeMap["Node_23"]->getOutputPort("dblevec"),
917                                 _nodeMap["Node_24"]->getInputPort("dblevec"));
918
919   // Corba sequence<double> -> Corba sequence<double>
920   _blocMap["Bloc_3"]->edAddLink(_nodeMap["Node_31"]->getOutputPort("lngvec"),
921                                 _nodeMap["Node_25"]->getInputPort("dblevec"));
922
923   _blocMap["Bloc_3"]->edAddLink(_nodeMap["Node_20"]->getOutputPort("long"),
924                                 _nodeMap["Node_22"]->getInputPort("double"));
925
926   _blocMap["Bloc_3"]->edAddLink(_nodeMap["Node_20"]->getOutputPort("long"),
927                                 _nodeMap["Node_22"]->getInputPort("long"));
928
929   _blocMap["Bloc_3"]->edAddLink(_nodeMap["Node_20"]->getOutputPort("str"),
930                                 _nodeMap["Node_22"]->getInputPort("str"));
931 }
932
933
934 void RuntimeTest::createDataLinksCORBAPython()
935 {
936   DEBTRACE(" --- create data links, CORBA to Python" );
937
938   CPPUNIT_ASSERT_THROW(_blocMap["Bloc_3"]->edAddLink(_nodeMap["Node_20"]->getOutputPort("double"),
939                                                      _nodeMap["Node_13"]->getInputPort("lng")),
940                        YACS::ENGINE::ConversionException);
941
942   CPPUNIT_ASSERT_THROW(_blocMap["Bloc_3"]->edAddLink(_nodeMap["Node_27"]->getOutputPort("strvec"),
943                                                      _nodeMap["Node_13"]->getInputPort("s")),
944                        YACS::ENGINE::ConversionException);
945
946
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"));
950
951   _blocMap["Bloc_3"]->edAddLink(_nodeMap["Node_21"]->getOutputPort("double"),
952                                 _nodeMap["Node_13"]->getInputPort("dble"));
953
954   _blocMap["Bloc_3"]->edAddLink(_nodeMap["Node_21"]->getOutputPort("long"),
955                                 _nodeMap["Node_13"]->getInputPort("lng"));
956
957   _blocMap["Bloc_3"]->edAddLink(_nodeMap["Node_21"]->getOutputPort("str"),
958                                 _nodeMap["Node_13"]->getInputPort("s"));
959
960   _blocMap["Bloc_3"]->edAddLink(_nodeMap["Node_21"]->getOutputPort("obj"),
961                                 _nodeMap["Node_13"]->getInputPort("ob"));
962
963   // --- Corba sequence<double> -> Python sequence<double>
964   _blocMap["Bloc_3"]->edAddLink(_nodeMap["Node_23"]->getOutputPort("dblevec"),
965                                 _nodeMap["Node_14"]->getInputPort("li"));
966
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"));
970
971   // --- Corba sequence<object> -> Python sequence<object>
972   _blocMap["Bloc_3"]->edAddLink(_nodeMap["Node_28"]->getOutputPort("objvec"),
973                                 _nodeMap["Node_14"]->getInputPort("lobj"));
974
975   // --- Corba sequence<string> -> Python sequence<string>
976   _blocMap["Bloc_3"]->edAddLink(_nodeMap["Node_27"]->getOutputPort("strvec"),
977                                 _nodeMap["Node_14"]->getInputPort("lstr"));
978
979   // --- Corba sequence<object> -> Python sequence<object>
980   _blocMap["Bloc_3"]->edAddLink(_nodeMap["Node_30"]->getOutputPort("objvecvec"),
981                                 _nodeMap["Node_14"]->getInputPort("llobj"));
982
983   _blocMap["Bloc_3"]->edAddLink(_nodeMap["Node_31"]->getOutputPort("lngvec"),
984                                 _nodeMap["Node_15"]->getInputPort("lngvec"));
985
986   _blocMap["Bloc_3"]->edAddLink(_nodeMap["Node_31"]->getOutputPort("lngvec"),
987                                 _nodeMap["Node_15"]->getInputPort("dblevec"));
988 }
989
990
991 void RuntimeTest::createDataLinksXML()
992 {
993   DEBTRACE(" --- create data links, xml nodes" );
994
995   CPPUNIT_ASSERT_THROW(_blocMap["Bloc_3"]->edAddLink(_nodeMap["Node_16"]->getOutputPort("c"),
996                                                      _nodeMap["Node_36"]->getInputPort("dblevec")),
997                        YACS::ENGINE::ConversionException);
998
999   CPPUNIT_ASSERT_THROW(_blocMap["Bloc_3"]->edAddLink(_nodeMap["Node_26"]->getOutputPort("dblevec"),
1000                                                      _nodeMap["Node_36"]->getInputPort("dble")),
1001                        YACS::ENGINE::ConversionException);
1002
1003   CPPUNIT_ASSERT_THROW(_blocMap["Bloc_3"]->edAddLink(_nodeMap["Node_36"]->getOutputPort("dblevec"),
1004                                                      _nodeMap["Node_33"]->getInputPort("dble")),
1005                        YACS::ENGINE::ConversionException);
1006
1007   CPPUNIT_ASSERT_THROW(_blocMap["Bloc_3"]->edAddLink(_nodeMap["Node_36"]->getOutputPort("dble"),
1008                                                      _nodeMap["Node_34"]->getInputPort("dblevec")),
1009                        YACS::ENGINE::ConversionException);
1010
1011   _blocMap["Bloc_3"]->edAddLink(_nodeMap["Node_16"]->getOutputPort("c"),
1012                                 _nodeMap["Node_36"]->getInputPort("dble"));
1013
1014   _blocMap["Bloc_3"]->edAddLink(_nodeMap["Node_26"]->getOutputPort("dblevec"),
1015                                 _nodeMap["Node_36"]->getInputPort("dblevec"));
1016
1017   _blocMap["Bloc_3"]->edAddLink(_nodeMap["Node_29"]->getOutputPort("dblevecvec"),
1018                                 _nodeMap["Node_36"]->getInputPort("dblevecvec"));
1019
1020   _blocMap["Bloc_3"]->edAddLink(_nodeMap["Node_36"]->getOutputPort("dble"),
1021                                 _nodeMap["Node_33"]->getInputPort("dble"));
1022
1023   _blocMap["Bloc_3"]->edAddLink(_nodeMap["Node_36"]->getOutputPort("dblevec"),
1024                                 _nodeMap["Node_34"]->getInputPort("dblevec"));
1025
1026   _blocMap["Bloc_3"]->edAddLink(_nodeMap["Node_36"]->getOutputPort("dblevecvec"),
1027                                 _nodeMap["Node_35"]->getInputPort("dblevecvec"));
1028 }
1029
1030
1031 void RuntimeTest::manualInitInputPort()
1032 {
1033   DEBTRACE(" --- InputPort initialization" );
1034   
1035   {
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++)
1040       {
1041         DEBTRACE(_blocMap["Bloc_3"]->getInPortName(*iter));
1042       }
1043   }
1044   _nodeMap["Node_10"]->getInputPort("a")->edInit(10.51);
1045
1046 //   CORBA::Any anyLong;
1047 //   anyLong <<= (CORBA::Long) 1;
1048   DEBTRACE("---");
1049   _nodeMap["Node_20"]->getInputPort("long")->edInit(1);
1050   DEBTRACE("---");
1051   
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)
1054
1055   CORBA::Any aString;
1056   aString <<= (const char *)"texte";
1057   _nodeMap["Node_20"]->getInputPort("str")->put(&aString);
1058 //  _nodeMap["Node_20"]->getInputPort("str")->edInit("texte");
1059   DEBTRACE("---");
1060
1061   {
1062     set<InputPort *> unitialized =  _blocMap["Bloc_3"]->edGetSetOfUnitializedInputPort();
1063     DEBTRACE(unitialized.size());
1064     CPPUNIT_ASSERT( _blocMap["Bloc_3"]->edAreAllInputPortInitialized() );
1065   }
1066
1067   {
1068     double d=10.51;
1069     int l;
1070     PyObject *pyob;
1071     CORBA::Any *any;
1072     Any * a;
1073     DEBTRACE("Python input port double");
1074     InputPort* inport=_nodeMap["Node_10"]->getInputPort("a");
1075
1076     DEBTRACE("Initialize port with C++ double value");
1077     a = AtomAny::New(d);
1078     inport->edInit("Cpp",a);
1079     a->decrRef();
1080     pyob=((InputPyPort*)inport)->getPyObj();
1081     DEBTRACE(pyob->ob_refcnt);
1082     CPPUNIT_ASSERT(PyFloat_AS_DOUBLE(pyob) == d);
1083
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);
1089
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.);
1095
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);
1103
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);
1113
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);
1121
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();
1127     CORBA::Long LL;
1128     *any >>= LL;
1129     l = LL;
1130     DEBTRACE("l = " << l);
1131     CPPUNIT_ASSERT(l == 10);
1132
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();
1138     *any >>= d;
1139     CPPUNIT_ASSERT_DOUBLES_EQUAL(10.51,d, 1e-12);
1140
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>");
1148
1149   }
1150 }
1151
1152 void RuntimeTest::manualExecuteNoThread()
1153 {
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();
1161
1162   DEBTRACE(" --- execution Python Node_12" );
1163   ((ElementaryNode*)_nodeMap["Node_12"])->load();
1164   ((ElementaryNode*)_nodeMap["Node_12"])->execute();
1165
1166   DEBTRACE(" --- execution CORBA Node_16" );
1167   ((ElementaryNode*)_nodeMap["Node_16"])->load();
1168   ((ElementaryNode*)_nodeMap["Node_16"])->execute();
1169
1170   DEBTRACE(" --- execution CORBA Node_17" );
1171   ((ElementaryNode*)_nodeMap["Node_17"])->load();
1172   ((ElementaryNode*)_nodeMap["Node_17"])->execute();
1173
1174   DEBTRACE(" --- execution CORBA Node_18" );
1175   ((ElementaryNode*)_nodeMap["Node_18"])->load();
1176   ((ElementaryNode*)_nodeMap["Node_18"])->execute();
1177
1178   DEBTRACE(" --- execution CORBA Node_19" );
1179   ((ElementaryNode*)_nodeMap["Node_19"])->load();
1180   ((ElementaryNode*)_nodeMap["Node_19"])->execute();
1181
1182   DEBTRACE(" --- execution CORBA Node_20" );
1183   ((ElementaryNode*)_nodeMap["Node_20"])->load();
1184   ((ElementaryNode*)_nodeMap["Node_20"])->execute();
1185
1186   DEBTRACE(" --- execution CORBA Node_21" );
1187   ((ElementaryNode*)_nodeMap["Node_21"])->load();
1188   ((ElementaryNode*)_nodeMap["Node_21"])->execute();
1189
1190   DEBTRACE(" --- execution CORBA Node_29" );
1191   ((ElementaryNode*)_nodeMap["Node_29"])->load();
1192   ((ElementaryNode*)_nodeMap["Node_29"])->execute();
1193
1194   DEBTRACE(" --- execution Python Node_13" );
1195   ((ElementaryNode*)_nodeMap["Node_13"])->load();
1196   ((ElementaryNode*)_nodeMap["Node_13"])->execute();
1197
1198   DEBTRACE(" --- execution CORBA Node_22" );
1199   ((ElementaryNode*)_nodeMap["Node_22"])->load();
1200   ((ElementaryNode*)_nodeMap["Node_22"])->execute();
1201
1202   DEBTRACE(" --- execution CORBA Node_23" );
1203   ((ElementaryNode*)_nodeMap["Node_23"])->load();
1204   ((ElementaryNode*)_nodeMap["Node_23"])->execute();
1205
1206   DEBTRACE(" --- execution CORBA Node_24" );
1207   ((ElementaryNode*)_nodeMap["Node_24"])->load();
1208   ((ElementaryNode*)_nodeMap["Node_24"])->execute();
1209
1210   DEBTRACE(" --- execution CORBA Node_27" );
1211   ((ElementaryNode*)_nodeMap["Node_27"])->load();
1212   ((ElementaryNode*)_nodeMap["Node_27"])->execute();
1213
1214   DEBTRACE(" --- execution CORBA Node_28" );
1215   ((ElementaryNode*)_nodeMap["Node_28"])->load();
1216   ((ElementaryNode*)_nodeMap["Node_28"])->execute();
1217
1218   DEBTRACE(" --- execution CORBA Node_30" );
1219   ((ElementaryNode*)_nodeMap["Node_30"])->load();
1220   ((ElementaryNode*)_nodeMap["Node_30"])->execute();
1221
1222   DEBTRACE(" --- execution CORBA Node_32" );
1223   ((ElementaryNode*)_nodeMap["Node_32"])->load();
1224   ((ElementaryNode*)_nodeMap["Node_32"])->execute();
1225
1226   DEBTRACE(" --- execution CORBA Node_26" );
1227   ((ElementaryNode*)_nodeMap["Node_26"])->load();
1228   ((ElementaryNode*)_nodeMap["Node_26"])->execute();
1229
1230   DEBTRACE(" --- execution CORBA Node_31" );
1231   ((ElementaryNode*)_nodeMap["Node_31"])->load();
1232   ((ElementaryNode*)_nodeMap["Node_31"])->execute();
1233
1234   DEBTRACE(" --- execution Python Node_14" );
1235   ((ElementaryNode*)_nodeMap["Node_14"])->load();
1236   ((ElementaryNode*)_nodeMap["Node_14"])->execute();
1237
1238   DEBTRACE(" --- execution Python Node_15" );
1239   ((ElementaryNode*)_nodeMap["Node_15"])->load();
1240   ((ElementaryNode*)_nodeMap["Node_15"])->execute();
1241
1242   std::cerr << __LINE__ << std::endl;
1243   DEBTRACE(" --- execution XML Node_36" );
1244   ((ElementaryNode*)_nodeMap["Node_36"])->load();
1245   ((ElementaryNode*)_nodeMap["Node_36"])->execute();
1246
1247   DEBTRACE(" --- execution CORBA Node_33" );
1248   ((ElementaryNode*)_nodeMap["Node_33"])->load();
1249   ((ElementaryNode*)_nodeMap["Node_33"])->execute();
1250
1251   DEBTRACE(" --- execution CORBA Node_34" );
1252   ((ElementaryNode*)_nodeMap["Node_34"])->load();
1253   ((ElementaryNode*)_nodeMap["Node_34"])->execute();
1254
1255   DEBTRACE(" --- execution CORBA Node_35" );
1256   ((ElementaryNode*)_nodeMap["Node_35"])->load();
1257   ((ElementaryNode*)_nodeMap["Node_35"])->execute();
1258
1259   DEBTRACE(" --- end of execution" );
1260 }
1261
1262
1263 void RuntimeTest::manualGetOutputs()
1264 {
1265   CORBA::Double l;
1266   CORBA::Any* x;
1267
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;
1275
1276   //   DEBTRACE("a: " << &a);
1277   //   DEBTRACE("a.value(): " << a.value());
1278
1279   x= ((InputCorbaPort*)_nodeMap["Node_16"]->getInputPort("a"))->getAny();
1280   DEBTRACE("CORBA Node_16 input a any: " << x);
1281   *x >>= l;
1282   DEBTRACE("CORBA Node_16 input a double: " << l);
1283
1284   *((InputCorbaPort*)_nodeMap["Node_17"]->getInputPort("b"))->getAny() >>= l;
1285   DEBTRACE("CORBA Node_17 input b double: " << l);
1286
1287   *((InputCorbaPort*)_nodeMap["Node_18"]->getInputPort("b"))->getAny() >>= l;
1288   DEBTRACE("CORBA Node_18 input a double: " << l);
1289
1290   *((OutputCorbaPort*)_nodeMap["Node_16"]->getOutputPort("c"))->getAny() >>= l;
1291   DEBTRACE("CORBA Node_16 output c double: " << l);
1292
1293   *((OutputCorbaPort*)_nodeMap["Node_17"]->getOutputPort("c"))->getAny() >>= l;
1294   DEBTRACE("CORBA Node_17 output c double: " << l);
1295
1296   *((OutputCorbaPort*)_nodeMap["Node_18"]->getOutputPort("c"))->getAny() >>= l;
1297   DEBTRACE("CORBA Node_18 output c double: " << l);
1298
1299   DEBTRACE(" --- fini" );
1300 }
1301
1302 void RuntimeTest::createCppNodes()
1303 {
1304     
1305   string s = "Node_Cpp";
1306   ElementaryNode* node = _myRuntime->createCompoNode("Cpp",s);
1307   _nodeMap[s] = node;
1308   InputPort  *i1  = node->edAddInputPort("id1",  _tc_double);
1309   InputPort  *i2  = node->edAddInputPort("ii2",  _tc_int);
1310
1311   OutputPort  *o3  = node->edAddOutputPort("os3",  _tc_string);
1312   
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"));
1318    
1319   CPPUNIT_ASSERT_EQUAL(node->getInputPort("id1"),i1);
1320   CPPUNIT_ASSERT_EQUAL(node->getOutputPort("os3"),o3);
1321   
1322   delete node;
1323 }
1324
1325 void RuntimeTest::convertPorts()
1326 {
1327   const char *type[] = { "Cpp", "CORBA", "Python", "XML" };
1328   int itype, jtype, ntypes = sizeof(type)/sizeof(const char *);
1329
1330   string s0 = "Node_";
1331   CORBA::Any  cAny;
1332   PyObject  * pAny;
1333   Any       * vAny;
1334   std::string sAny;
1335   
1336   for (itype=0; itype<ntypes-1; itype++) 
1337     {
1338       string s = s0 + type[itype];
1339       
1340       cerr << endl;
1341       DEBTRACE("Node " << type[itype] << " creation");
1342       ElementaryNode* node;
1343       switch (itype) 
1344         {
1345         case 1:
1346           node = _myRuntime->createRefNode(type[itype],s);
1347           break;
1348         case 2: 
1349           node = _myRuntime->createScriptNode(type[itype], s);
1350           break;
1351         case 3:
1352           node = _myRuntime->createRefNode("xmlsh",s);
1353           break;
1354         default:
1355           node = _myRuntime->createCompoNode(type[itype], s);
1356           break;
1357         }
1358       InputPort  *inport  = node->edAddInputPort("id1",  _tc_double);
1359       CPPUNIT_ASSERT(NULL != node);
1360       for (jtype=0; jtype < ntypes; jtype++) 
1361         {
1362           double d0= itype * 10 + jtype, d1;
1363           InputPort* pwrap=_myRuntime->adapt(inport, type[jtype], _tc_double);
1364
1365           const void *v;
1366           switch (jtype) 
1367             {
1368             case 0:
1369             case 4:
1370               v = vAny = AtomAny::New(d0);
1371               break;
1372             case 1:
1373               v = &cAny;
1374               cAny <<= (CORBA::Double) d0;
1375               break;
1376             case 2:
1377               v = pAny = PyFloat_FromDouble(d0);
1378               break;
1379             case 3:
1380               { 
1381                 ostringstream os;
1382                 os << "<value><double>" << d0 << "</double></value>";
1383                 sAny = os.str();
1384                 v = sAny.c_str();
1385               }
1386               break;
1387             default:
1388               v = NULL;
1389               break;
1390             }
1391
1392             if ((itype == 2) && (jtype == 2)) 
1393               {
1394                 std::cerr << "s = " << s << endl;
1395               }
1396
1397             DEBTRACE("Put a " << type[jtype] << " double (" << d0 << ") in " << s);
1398             if (jtype == 2) 
1399               {
1400                 PyGILState_STATE gstate = PyGILState_Ensure();
1401                 pwrap->put(v);
1402                 PyGILState_Release(gstate);
1403               }
1404             else
1405               pwrap->put(v);
1406             cerr << endl;
1407
1408             switch (itype)
1409               {
1410               case 0:
1411               case 4: 
1412                 {
1413                   Any * a=((InputCppPort*)inport)->getCppObj();
1414                   CPPUNIT_ASSERT(a->getType()->isA(_tc_double));
1415                   d1 = a->getDoubleValue();
1416                 }
1417                 break;
1418               case 1:
1419                 {
1420                   CORBA::Any * a = ((InputCorbaPort*)inport)->getAny();
1421                   CPPUNIT_ASSERT(a->type()->equal(CORBA::_tc_double));
1422                   CORBA::Double d;
1423                   *a >>= d;
1424                   d1 = d;
1425                 }
1426                 break;
1427               case 2:
1428                 {
1429                   PyObject *a = ((InputPyPort*)inport)->getPyObj();
1430                   CPPUNIT_ASSERT(PyFloat_Check(a));
1431                   d1 = PyFloat_AsDouble(a);
1432                 }
1433                 break;
1434               case 3:
1435                 {
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--;
1440                   a1 = a;
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>")));
1445                   char *err;
1446                   d1 = strtod(a2, &err);
1447                   CPPUNIT_ASSERT(err == a3);
1448                 }
1449                 break;
1450               }
1451           
1452             CPPUNIT_ASSERT_DOUBLES_EQUAL(d0, d1, 1e-12);
1453          
1454             switch (jtype) 
1455               {
1456               case 0:
1457               case 4:
1458                 vAny->decrRef();
1459                 break;
1460               case 2:
1461                 Py_DECREF(pAny);
1462                 break;
1463               default:
1464                 break;
1465               }
1466           if (pwrap != inport) delete pwrap;
1467         }
1468       delete node;
1469     }
1470 }
1471
1472 void myTestRun(int nIn, int nOut, Any **In, Any **Out) throw (YACS::Exception)
1473 {
1474   double x, y;
1475   cerr << "myTestRun nIn = " << nIn << endl;
1476   cerr << "myTestRun nOut = " << nOut << endl;
1477
1478   x = In[0]->getDoubleValue();
1479
1480   if (x >= 0.0)
1481     {
1482       y = sqrt(x);
1483       Out[0] = AtomAny::New(y);
1484     }
1485   else 
1486     {
1487       throw YACS::Exception("myTestRun : input must be a positive or null real");
1488     }
1489 }
1490
1491
1492 void RuntimeTest::executeCppNode()
1493 {
1494   cerr << endl << endl;
1495   
1496   Any *u, *v, *w;
1497   double du, dv, dw;
1498   
1499   DEBTRACE("execute a CppNode with an internal C++ implementation")
1500   ServiceNode * node = _myRuntime->createCompoNode("Cpp", "test");
1501   ((CppNode *) node)->setFunc(myTestRun);
1502   
1503   InputPort  *in  = node->edAddInputPort("in",  _tc_double);
1504   OutputPort  *out  = node->edAddOutputPort("out",  _tc_double);
1505   node->load();
1506
1507   dv = 4.5;
1508   v = AtomAny::New(dv);
1509   in->edInit("Cpp",v);
1510   
1511   node->execute();
1512   
1513   w = ((OutputCppPort *) out)->get();
1514   dw = w->getDoubleValue();
1515   
1516   cerr << "sqrt(" << dv << ") = " << dw << endl;
1517   CPPUNIT_ASSERT_DOUBLES_EQUAL(dw, sqrt(dv), 1e-12);
1518   
1519   u = AtomAny::New((double) -3.5);
1520   in->edInit("Cpp",u);
1521   CPPUNIT_ASSERT_THROW(node->execute(), YACS::Exception);
1522   
1523   u->decrRef();
1524   v->decrRef();
1525   
1526   delete node;
1527   
1528   DEBTRACE("execute a CppNode with an external C++ implementation (in a dynamic library)");
1529   
1530   node = _myRuntime->createCompoNode("Cpp", "test");
1531   CppComponent * C = new CppComponent("TestComponent");
1532   node->setComponent(C);
1533   C->decrRef();
1534   node->setMethod("f");
1535   
1536   in  = node->edAddInputPort("in",  _tc_double);
1537   out  = node->edAddOutputPort("out",  _tc_double);
1538   node->load();
1539
1540   dv = 4.5;
1541   v = AtomAny::New(dv);
1542   in->edInit("Cpp",v);
1543   
1544   node->execute();
1545   
1546   w = ((OutputCppPort *) out)->get();
1547   dw = w->getDoubleValue();
1548   
1549   cerr << "sqrt(" << dv << ") = " << dw << endl;
1550   CPPUNIT_ASSERT_DOUBLES_EQUAL(dw, sqrt(dv), 1e-12);
1551   
1552   u = AtomAny::New((double) -3.5);
1553   in->edInit("Cpp",u);
1554   CPPUNIT_ASSERT_THROW(node->execute(), YACS::Exception);
1555   
1556   u->decrRef();
1557   v->decrRef();
1558   
1559   delete node;
1560   
1561 }
1562
1563 void RuntimeTest::createGraphWithCppNodes()
1564 {
1565   ElementaryNode * n1, * n2;
1566   InputPort  *in1, *in2;
1567   OutputPort  *out1, *out2;
1568
1569   n1 = _myRuntime->createCompoNode(CppNode::KIND, "test1");
1570   n2 = _myRuntime->createScriptNode(PythonNode::KIND, "test2");
1571    
1572   CppComponent *C = new CppComponent("TestComponent"); 
1573   ((CppNode *) n1)->setComponent(C);
1574   C->decrRef();
1575   ((CppNode *) n1)->setMethod("f");
1576   in1  = n1->edAddInputPort("i",  _tc_double);
1577   out1  = n1->edAddOutputPort("o",  _tc_double);
1578   
1579   ((InlineNode*) n2)->setScript("a=a+1\n");
1580   in2  = n2->edAddInputPort("a",  _tc_double);
1581   out2  = n2->edAddOutputPort("a",  _tc_double);
1582     
1583   Bloc * loopBody = _myRuntime->createBloc("LoopBody");
1584   loopBody->edAddChild(n1);
1585   loopBody->edAddChild(n2);
1586   loopBody->edAddLink(out1, in2);
1587   loopBody->edAddLink(out2, in1);
1588     
1589   ForLoop *loop=_myRuntime->createForLoop("Loop");
1590   loop->edSetNode(loopBody);
1591   InputPort *iNbTimes=loop->edGetNbOfTimesInputPort();
1592   iNbTimes->edInit(5);
1593     
1594   Bloc * graph = _myRuntime->createBloc("graph");
1595   graph->edAddChild(loop);
1596     
1597   DEBTRACE("n1->getInputPort(\"in\") = " << n1->getInputPort("i")->getName())
1598     
1599   in1->edInit(4.5);
1600   in2->edInit(0.0);
1601     
1602   Executor exe;
1603   exe.RunW(graph);
1604     
1605   DEBTRACE(out2->dump());
1606     
1607   delete graph;
1608 }
1609
1610 void RuntimeTest::classTeardown()
1611 {
1612   if (endTests) return;
1613   
1614   endTests = true;
1615
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"];
1624
1625   _tc_seqC->decrRef();
1626   _tc_C->decrRef();
1627   list<TypeCodeObjref *>::iterator i;
1628   for (i=_ltc.begin(); i != _ltc.end(); i++)
1629     (*i)->decrRef();
1630
1631   _tc_seqseqobj->decrRef();
1632   _tc_seqobj->decrRef();
1633
1634
1635   _tc->decrRef();
1636   _tc_seqseqdble->decrRef();
1637   _tc_seqdble->decrRef();
1638   _tc_seqstr->decrRef();
1639   _tc_seqlong->decrRef();
1640   _tc_string->decrRef();
1641
1642   _myRuntime->fini();
1643   delete _myRuntime;
1644 }
1645