]> SALOME platform Git repositories - modules/yacs.git/blob - src/engine/Test/engineIntegrationTest.cxx
Salome HOME
copy tag mergefrom_BR_V0_1_CC_Salome_04oct07
[modules/yacs.git] / src / engine / Test / engineIntegrationTest.cxx
1 #include "engineIntegrationTest.hxx"
2 #include "RuntimeForEngineIntegrationTest.hxx"
3 #include "ComponentInstanceTest.hxx"
4 #include "OutputDataStreamPort.hxx"
5 #include "InputDataStreamPort.hxx"
6 #include "ContainerTest.hxx"
7 #include "OptimizerLoop.hxx"
8 #include "ForEachLoop.hxx"
9 #include "WhileLoop.hxx"
10 #include "TypeCode.hxx"
11 #include "Executor.hxx"
12 #include "LinkInfo.hxx"
13 #include "ForLoop.hxx"
14 #include "ToyNode.hxx"
15 #include "Switch.hxx"
16 #include "Bloc.hxx"
17 #include "Proc.hxx"
18
19 #include <iostream>
20
21 //#define _DEVDEBUG_
22 #include "YacsTrace.hxx"
23
24 using namespace std;
25
26 #define DBL_PRECISION_COMPARE 1.e-12
27
28 using namespace YACS::ENGINE;
29
30 void EngineIntegrationTest::setUp()
31 {
32   RuntimeForEngineIntegrationTest::setRuntime();
33 }
34
35 void EngineIntegrationTest::tearDown()
36 {
37 }
38
39 //Simplest test to test basic mechanisms like Data, initialisation of ports.
40 void EngineIntegrationTest::testBloc1()
41 {
42   ToyNode *n1=new ToyNode("T1");
43   InputPort *i8=n1->edAddInputPort("o",Runtime::_tc_double);
44   InputPort *i9=n1->edAddInputPort("p",Runtime::_tc_double);
45   Bloc *graph=new Bloc("toto");
46   graph->edAddChild(n1);
47   OutputPort *o1=n1->edAddOutputPort("b",Runtime::_tc_double);
48   i9->edInit(5.67);
49   i8->edInit(2.78);
50   Executor exe;
51   exe.RunW(graph);
52   CPPUNIT_ASSERT_DOUBLES_EQUAL( ((OutputToyPort*)o1)->get()->getDoubleValue(),8.45,DBL_PRECISION_COMPARE );
53   OutputPort *o2=n1->edAddOutputPort("c",Runtime::_tc_double);
54   exe.RunW(graph);
55   CPPUNIT_ASSERT_DOUBLES_EQUAL( ((OutputToyPort*)o1)->get()->getDoubleValue(),4.225,DBL_PRECISION_COMPARE );
56   Executor exe2;
57   Bloc *clonedGraph=(Bloc *)graph->clone(0);
58   delete graph;
59   exe2.RunW(clonedGraph);
60   CPPUNIT_ASSERT_DOUBLES_EQUAL( ((OutputToyPort*)clonedGraph->getOutputPort("T1.b"))->get()->getDoubleValue(),4.225,DBL_PRECISION_COMPARE );
61   delete clonedGraph;
62 }
63
64 //Only one level(hierarchy) simple graph. Tests DF and CF links.
65 void EngineIntegrationTest::testBloc2()
66 {
67   ToyNode *n1=new ToyNode("T1");
68   ToyNode *n2=new ToyNode("T2");
69   ToyNode *n3=new ToyNode("T3");
70   ToyNode *n4=new ToyNode("T4");
71   Bloc *graph=new Bloc("Global");
72   graph->edAddChild(n1); graph->edAddChild(n2); graph->edAddChild(n3); graph->edAddChild(n4);
73   InputPort *i1_a=n1->edAddInputPort("a",Runtime::_tc_double); InputPort *i1_b=n1->edAddInputPort("b",Runtime::_tc_double); OutputPort *o1_j=n1->edAddOutputPort("j",Runtime::_tc_double); OutputPort *o1_k=n1->edAddOutputPort("k",Runtime::_tc_double);
74   InputPort *i2_c=n2->edAddInputPort("c",Runtime::_tc_double); InputPort *i2_d=n2->edAddInputPort("d",Runtime::_tc_double); OutputPort *o2_f=n2->edAddOutputPort("f",Runtime::_tc_double);
75   InputPort *i3_e=n3->edAddInputPort("e",Runtime::_tc_double); OutputPort *o3_g=n3->edAddOutputPort("g",Runtime::_tc_double); OutputPort *o3_h=n3->edAddOutputPort("h",Runtime::_tc_double);
76   InputPort *i4_l=n4->edAddInputPort("l",Runtime::_tc_double); InputPort *i4_m=n4->edAddInputPort("m",Runtime::_tc_double); OutputPort *o4_i=n4->edAddOutputPort("i",Runtime::_tc_double);
77   //Retrieving gates
78   InGate *iN1=n1->getInGate(); InGate *iN2=n2->getInGate(); InGate *iN3=n3->getInGate(); InGate *iN4=n4->getInGate();
79   OutGate *oN1=n1->getOutGate(); OutGate *oN2=n2->getOutGate(); OutGate *oN3=n3->getOutGate(); OutGate *oN4=n4->getOutGate();
80   i1_a->edInit(1.2);
81   i1_b->edInit(3.4);
82   i2_d->edInit(7.);
83   //DF                                                                      //CF
84   graph->edAddLink(o1_j,i2_c);                                              graph->edAddLink(oN1,iN2);
85   graph->edAddLink(o1_k,i3_e);                                              graph->edAddLink(oN1,iN3);
86   graph->edAddLink(o2_f,i4_l);                                              graph->edAddLink(oN2,iN4);
87   graph->edAddLink(o3_g,i4_m);                                              graph->edAddLink(oN3,iN4);
88   Executor exe;
89   exe.RunW(graph);
90   CPPUNIT_ASSERT_DOUBLES_EQUAL( ((OutputToyPort*)o4_i)->get()->getDoubleValue(),10.45,DBL_PRECISION_COMPARE );
91   exe.RunW(graph);
92   CPPUNIT_ASSERT_DOUBLES_EQUAL( ((OutputToyPort*)o4_i)->get()->getDoubleValue(),10.45,DBL_PRECISION_COMPARE );
93   Executor exe2;
94   Bloc *clonedGraph=(Bloc *)graph->clone(0);
95   exe2.RunW(clonedGraph);
96   CPPUNIT_ASSERT_DOUBLES_EQUAL( ((OutputToyPort*)clonedGraph->getOutputPort("T4.i"))->get()->getDoubleValue(),10.45,DBL_PRECISION_COMPARE );
97   delete clonedGraph;
98   bool testOfCycleSucceed=false;
99   try
100     { graph->edAddLink(oN4,iN1); }
101   catch(YACS::Exception &e)
102     { if(strcmp(e.what(),"Cycle has been detected")==0)
103       testOfCycleSucceed=true; }
104   CPPUNIT_ASSERT(testOfCycleSucceed);
105   delete graph;
106 }
107
108 //test multi level graphs
109 void EngineIntegrationTest::testBloc3()
110 {
111   Bloc *toto=new Bloc("toto");
112   Bloc *tata=new Bloc("tata");
113   Bloc *titi=new Bloc("titi");
114   ToyNode *n2=new ToyNode("T2"); ToyNode *n3=new ToyNode("T3"); ToyNode *n4=new ToyNode("T4"); ToyNode *n5=new ToyNode("T5"); ToyNode *n6=new ToyNode("T6");
115   ToyNode *n7=new ToyNode("T7"); ToyNode *n8=new ToyNode("T8");
116   toto->edAddChild(titi); titi->edAddChild(tata); titi->edAddChild(n3); toto->edAddChild(n2); tata->edAddChild(n4); tata->edAddChild(n5); tata->edAddChild(n6);
117   titi->edAddChild(n7); titi->edAddChild(n8);
118   CPPUNIT_ASSERT( toto->edAddCFLink(n2,titi) );
119   CPPUNIT_ASSERT( !toto->edAddCFLink(n2,titi) );
120   toto->edAddCFLink(n3,tata); toto->edAddCFLink(n5,n4); titi->edAddCFLink(n7,n8); titi->edAddCFLink(tata,n8);
121   //
122   InputPort *i2_a=n2->edAddInputPort("a",Runtime::_tc_double); OutputPort *o2_a=n2->edAddOutputPort("a",Runtime::_tc_double); OutputPort *o2_b=n2->edAddOutputPort("b",Runtime::_tc_double);
123   InputPort *i3_a=n3->edAddInputPort("a",Runtime::_tc_double); OutputPort *o3_a=n3->edAddOutputPort("a",Runtime::_tc_double); OutputPort *o3_b=n3->edAddOutputPort("b",Runtime::_tc_double);
124   InputPort *i4_a=n4->edAddInputPort("a",Runtime::_tc_double); InputPort *i4_b=n4->edAddInputPort("b",Runtime::_tc_double); OutputPort *o4_a=n4->edAddOutputPort("a",Runtime::_tc_double); OutputPort *o4_b=n4->edAddOutputPort("b",Runtime::_tc_double);
125   InputPort *i5_a=n5->edAddInputPort("a",Runtime::_tc_double); InputPort *i5_b=n5->edAddInputPort("b",Runtime::_tc_double); OutputPort *o5_a=n5->edAddOutputPort("a",Runtime::_tc_double);
126   InputPort *i6_a=n6->edAddInputPort("a",Runtime::_tc_double); InputPort *i6_b=n6->edAddInputPort("b",Runtime::_tc_double); OutputPort *o6_a=n6->edAddOutputPort("a",Runtime::_tc_double);
127   InputPort *i7_a=n7->edAddInputPort("a",Runtime::_tc_double); OutputPort *o7_a=n7->edAddOutputPort("a",Runtime::_tc_double);
128   InputPort *i8_a=n8->edAddInputPort("a",Runtime::_tc_double); InputPort *i8_b=n8->edAddInputPort("b",Runtime::_tc_double); OutputPort *o8_a=n8->edAddOutputPort("a",Runtime::_tc_double);
129   //
130   toto->edAddLink(o2_a,i3_a);  toto->edAddLink(o3_a,i5_a); toto->edAddLink(o2_b,i5_b); toto->edAddLink(o2_a,i4_b);
131   toto->edAddLink(o3_b,i6_a); toto->edAddLink(o6_a,i8_a); toto->edAddLink(o7_a,i8_b);
132   //
133   i2_a->edInit(1.2);
134   i6_b->edInit(7.);
135   i4_a->edInit(7.);
136   i7_a->edInit(3.);
137   CPPUNIT_ASSERT_EQUAL( 1, toto->getNumberOfCFLinks() ); CPPUNIT_ASSERT_EQUAL( 3, titi->getNumberOfCFLinks() );
138   CPPUNIT_ASSERT_EQUAL( 1, tata->getNumberOfCFLinks() );
139   Executor exe;
140   exe.RunW(toto);
141   CPPUNIT_ASSERT_EQUAL(toto->getState(),YACS::DONE);
142   CPPUNIT_ASSERT_EQUAL(titi->getState(),YACS::DONE);
143   CPPUNIT_ASSERT_EQUAL(tata->getState(),YACS::DONE);
144   CPPUNIT_ASSERT_DOUBLES_EQUAL( ((OutputToyPort*)o6_a)->get()->getDoubleValue(),7.3,DBL_PRECISION_COMPARE );
145   CPPUNIT_ASSERT_DOUBLES_EQUAL( ((OutputToyPort*)o4_a)->get()->getDoubleValue(),3.8,DBL_PRECISION_COMPARE );
146   CPPUNIT_ASSERT_DOUBLES_EQUAL( ((OutputToyPort*)o8_a)->get()->getDoubleValue(),10.3,DBL_PRECISION_COMPARE );
147   exe.RunW(toto);
148   CPPUNIT_ASSERT_EQUAL(toto->getState(),YACS::DONE);
149   CPPUNIT_ASSERT_EQUAL(titi->getState(),YACS::DONE);
150   CPPUNIT_ASSERT_EQUAL(tata->getState(),YACS::DONE);
151   CPPUNIT_ASSERT_DOUBLES_EQUAL( ((OutputToyPort*)o6_a)->get()->getDoubleValue(),7.3,DBL_PRECISION_COMPARE );
152   CPPUNIT_ASSERT_DOUBLES_EQUAL( ((OutputToyPort*)o4_a)->get()->getDoubleValue(),3.8,DBL_PRECISION_COMPARE );
153   CPPUNIT_ASSERT_DOUBLES_EQUAL( ((OutputToyPort*)o8_a)->get()->getDoubleValue(),10.3,DBL_PRECISION_COMPARE );
154   Bloc *clonedGraph=(Bloc *)toto->clone(0);
155   Bloc *titiCloned=(Bloc *)titi->clone(0);//to check internal links only cpy
156   CPPUNIT_ASSERT_EQUAL(4,(int)titiCloned->getSetOfInternalLinks().size());
157   CPPUNIT_ASSERT_EQUAL(7,(int)clonedGraph->getSetOfInternalLinks().size());
158   delete titiCloned;
159   titi->edRemoveChild(n7);
160   delete n7;
161   CPPUNIT_ASSERT_EQUAL( toto->getNumberOfCFLinks(),1 ); CPPUNIT_ASSERT_EQUAL( titi->getNumberOfCFLinks(),2 );
162   CPPUNIT_ASSERT_EQUAL( tata->getNumberOfCFLinks(),1 );
163   titi->edRemoveChild(tata);
164   delete tata;
165   CPPUNIT_ASSERT_EQUAL( 1, toto->getNumberOfCFLinks() ); CPPUNIT_ASSERT_EQUAL( 0, titi->getNumberOfCFLinks() );
166   delete toto;
167   Executor exe2;
168   exe2.RunW(clonedGraph);
169   CPPUNIT_ASSERT_DOUBLES_EQUAL( ((OutputToyPort*)clonedGraph->getOutputPort("titi.tata.T6.a"))->get()->getDoubleValue(),7.3,DBL_PRECISION_COMPARE );
170   CPPUNIT_ASSERT_DOUBLES_EQUAL( ((OutputToyPort*)clonedGraph->getOutputPort("titi.tata.T4.a"))->get()->getDoubleValue(),3.8,DBL_PRECISION_COMPARE );
171   CPPUNIT_ASSERT_DOUBLES_EQUAL( ((OutputToyPort*)clonedGraph->getOutputPort("titi.T8.a"))->get()->getDoubleValue(),10.3,DBL_PRECISION_COMPARE );
172   delete clonedGraph;
173 }
174
175 void EngineIntegrationTest::testForLoop1()
176 {
177   TypeCode *tc_double    = Runtime::_tc_double;
178   TypeCode *tc_int       = Runtime::_tc_int;
179   ToyNode *n1=new ToyNode("T1");
180   InputPort *i11=n1->edAddInputPort("i11",tc_double);
181   i11->edInit(3.14);
182   InputPort *i12=n1->edAddInputPort("i12",tc_double);
183   i12->edInit(2.78);
184   InputPort *i13=n1->edAddInputPort("i13",tc_double);
185   i13->edInit(7.177);
186   OutputPort *o1=n1->edAddOutputPort("o1",tc_double);
187   OutputPort *o2=n1->edGetNbOfInputsOutputPort();
188   Bloc *graph=new Bloc("Graph");
189   graph->edAddChild(n1);
190   Bloc *titi=new Bloc("titi");
191   ForLoop *loop=new ForLoop("toto");
192   ToyNode *n2=new ToyNode("T2");
193   titi->edAddChild(n2);
194   InputPort *i21=n2->edAddInputPort("i1",tc_double);
195   InputPort *i22=n2->edAddInputPort("i2",tc_double);
196   i22->edInit(2.1);
197   OutputPort *o21=n2->edAddOutputPort("o1",tc_double);
198   loop->edSetNode(titi);
199   graph->edAddChild(loop);
200   InputPort *iNbTimes=loop->edGetNbOfTimesInputPort();
201   graph->edAddLink(o2,iNbTimes);
202   graph->edAddLink(o1,i21);
203   graph->edAddCFLink(n1,loop);
204   graph->edAddLink(o21,i21);
205   Executor exe;
206   exe.RunW(graph);
207   CPPUNIT_ASSERT_DOUBLES_EQUAL( ((OutputToyPort*)n2->getOutputPort("o1"))->get()->getDoubleValue(),19.397, DBL_PRECISION_COMPARE);
208   CPPUNIT_ASSERT_EQUAL(loop->getNbOfTurns(),3);
209   CPPUNIT_ASSERT_EQUAL(loop->getState(),YACS::DONE);
210   CPPUNIT_ASSERT_EQUAL(graph->getState(),YACS::DONE);
211   exe.RunW(graph);
212   CPPUNIT_ASSERT_DOUBLES_EQUAL( ((OutputToyPort*)n2->getOutputPort("o1"))->get()->getDoubleValue(),19.397, DBL_PRECISION_COMPARE);
213   CPPUNIT_ASSERT_EQUAL(loop->getNbOfTurns(),3);
214   CPPUNIT_ASSERT_EQUAL(loop->getState(),YACS::DONE);
215   CPPUNIT_ASSERT_EQUAL(graph->getState(),YACS::DONE);
216   Bloc *clonedGraph=(Bloc *)graph->clone(0);
217   delete graph;
218   Executor exe2;
219   exe2.RunW(clonedGraph);
220   CPPUNIT_ASSERT_DOUBLES_EQUAL( ((OutputToyPort*)clonedGraph->getOutputPort("toto.titi.T2.o1"))->get()->getDoubleValue(),19.397, DBL_PRECISION_COMPARE);
221   CPPUNIT_ASSERT_EQUAL(((Loop *)clonedGraph->getChildByName("toto"))->getNbOfTurns(),3);
222   CPPUNIT_ASSERT_EQUAL(clonedGraph->getChildByName("toto")->getState(),YACS::DONE);
223   CPPUNIT_ASSERT_EQUAL(clonedGraph->getState(),YACS::DONE);
224   delete clonedGraph;
225 }
226
227 void EngineIntegrationTest::testForLoop2()
228 {
229   TypeCode *tc_double    = Runtime::_tc_double;
230   TypeCode *tc_int       = Runtime::_tc_int;
231   ToyNode *n1=new ToyNode("T1");
232   InputPort *i11=n1->edAddInputPort("i11",tc_double);
233   i11->edInit(3.14);
234   InputPort *i12=n1->edAddInputPort("i12",tc_double);
235   i12->edInit(2.78);
236   InputPort *i13=n1->edAddInputPort("i13",tc_double);
237   i13->edInit(7.177);
238   OutputPort *o1=n1->edAddOutputPort("o1",tc_double);
239   OutputPort *o2=n1->edGetNbOfInputsOutputPort();
240   Bloc *graph=new Bloc("Graph");
241   graph->edAddChild(n1);
242   ForLoop *loop=new ForLoop("toto");
243   ToyNode *n2=new ToyNode("T2");
244   InputPort *i21=n2->edAddInputPort("i1",tc_double);
245   InputPort *i22=n2->edAddInputPort("i2",tc_double);
246   i22->edInit(2.1);
247   OutputPort *o21=n2->edAddOutputPort("o1",tc_double);
248   loop->edSetNode(n2);
249   graph->edAddChild(loop);
250   InputPort *iNbTimes=loop->edGetNbOfTimesInputPort();
251   graph->edAddLink(o2,iNbTimes);
252   graph->edAddLink(o1,i21);
253   graph->edAddCFLink(n1,loop);
254   graph->edAddLink(o21,i21);
255   Executor exe;
256   exe.RunW(graph);
257   CPPUNIT_ASSERT_DOUBLES_EQUAL( ((OutputToyPort*)n2->getOutputPort("o1"))->get()->getDoubleValue(),19.397, DBL_PRECISION_COMPARE);
258   CPPUNIT_ASSERT_EQUAL(loop->getNbOfTurns(),3);
259   CPPUNIT_ASSERT_EQUAL(loop->getState(),YACS::DONE);
260   CPPUNIT_ASSERT_EQUAL(graph->getState(),YACS::DONE);
261   exe.RunW(graph);
262   CPPUNIT_ASSERT_DOUBLES_EQUAL( ((OutputToyPort*)n2->getOutputPort("o1"))->get()->getDoubleValue(),19.397, DBL_PRECISION_COMPARE);
263   CPPUNIT_ASSERT_EQUAL(loop->getNbOfTurns(),3);
264   CPPUNIT_ASSERT_EQUAL(loop->getState(),YACS::DONE);
265   CPPUNIT_ASSERT_EQUAL(graph->getState(),YACS::DONE);
266   delete graph;
267 }
268
269 //Test on loop when 0 turn of forloop is done
270 void EngineIntegrationTest::testForLoop3()
271 {
272   TypeCode *tc_double    = Runtime::_tc_double;
273   TypeCode *tc_int       = Runtime::_tc_int;
274   ToyNode *n1=new ToyNode("T1");
275   InputPort *i11=n1->edAddInputPort("i11",tc_double);
276   i11->edInit(3.14);
277   InputPort *i12=n1->edAddInputPort("i12",tc_double);
278   i12->edInit(2.78);
279   OutputPort *o11=n1->edAddOutputPort("o1",tc_double);
280   OutputPort *o12=n1->edGetNbOfInputsOutputPort();
281   ToyNode *n2=new ToyNode("T2");
282   InputPort *i21=n2->edAddInputPort("i1",tc_double);
283   InputPort *i22=n2->edAddInputPort("i2",tc_double);
284   i22->edInit(2.1);
285   OutputPort *o21=n2->edAddOutputPort("o1",tc_double);
286   ToyNode *n3=new ToyNode("T3");
287   InputPort *i31=n3->edAddInputPort("i1",tc_double);
288   OutputPort *o31=n3->edAddOutputPort("o1",tc_double);
289   ForLoop *loop=new ForLoop("toto");
290   loop->edSetNode(n2);
291   Bloc *graph=new Bloc("Graph");
292   graph->edAddChild(loop);
293   graph->edAddChild(n1);
294   graph->edAddChild(n3);
295   graph->edAddCFLink(n1,loop);
296   graph->edAddCFLink(loop,n3);
297   graph->edAddLink(o11,i21);
298   graph->edAddLink(o12,loop->edGetNbOfTimesInputPort());
299   graph->edAddLink(o21,i21);
300   graph->edAddLink(o21,i31);
301   Executor exe;
302   exe.RunW(graph);
303   CPPUNIT_ASSERT_DOUBLES_EQUAL( ((OutputToyPort*)graph->getOutputPort("T3.o1"))->get()->getDoubleValue(),10.12, DBL_PRECISION_COMPARE);
304   CPPUNIT_ASSERT_EQUAL(loop->getNbOfTurns(),2);
305   CPPUNIT_ASSERT_EQUAL(loop->getState(),YACS::DONE);
306   CPPUNIT_ASSERT_EQUAL(graph->getState(),YACS::DONE);
307   CPPUNIT_ASSERT_EQUAL(n1->getState(),YACS::DONE);
308   CPPUNIT_ASSERT_EQUAL(n3->getState(),YACS::DONE);
309   exe.RunW(graph);
310   CPPUNIT_ASSERT_DOUBLES_EQUAL( ((OutputToyPort*)graph->getOutputPort("T3.o1"))->get()->getDoubleValue(),10.12, DBL_PRECISION_COMPARE);
311   CPPUNIT_ASSERT_EQUAL(loop->getNbOfTurns(),2);
312   CPPUNIT_ASSERT_EQUAL(loop->getState(),YACS::DONE);
313   CPPUNIT_ASSERT_EQUAL(graph->getState(),YACS::DONE);
314   CPPUNIT_ASSERT_EQUAL(n1->getState(),YACS::DONE);
315   CPPUNIT_ASSERT_EQUAL(n3->getState(),YACS::DONE);
316   //Let's go to test 0 cycle whithout any back dependancies : normal behaviour
317   n1->edRemovePort(i11);
318   n1->edRemovePort(i12);
319   graph->edRemoveLink(o21,i31);
320   graph->edAddLink(o11,i31);
321   exe.RunW(graph);
322   CPPUNIT_ASSERT_EQUAL(loop->getState(),YACS::DONE);
323   CPPUNIT_ASSERT_EQUAL(loop->getNbOfTurns(),0);
324   CPPUNIT_ASSERT_EQUAL(graph->getState(),YACS::DONE);
325   CPPUNIT_ASSERT_EQUAL(n1->getState(),YACS::DONE);
326   CPPUNIT_ASSERT_EQUAL(n3->getState(),YACS::DONE);
327   exe.RunW(graph);
328   CPPUNIT_ASSERT_EQUAL(loop->getState(),YACS::DONE);
329   CPPUNIT_ASSERT_EQUAL(loop->getNbOfTurns(),0);
330   CPPUNIT_ASSERT_EQUAL(graph->getState(),YACS::DONE);
331   CPPUNIT_ASSERT_EQUAL(n1->getState(),YACS::DONE);
332   CPPUNIT_ASSERT_EQUAL(n3->getState(),YACS::DONE);
333   Bloc *clonedGraph=(Bloc *)graph->clone(0);
334   Executor exe2;
335   exe2.RunW(clonedGraph);
336   CPPUNIT_ASSERT_EQUAL(((Loop *)clonedGraph->getChildByName("toto"))->getState(),YACS::DONE);
337   CPPUNIT_ASSERT_EQUAL(((Loop *)clonedGraph->getChildByName("toto"))->getNbOfTurns(),0);
338   CPPUNIT_ASSERT_EQUAL(clonedGraph->getState(),YACS::DONE);
339   CPPUNIT_ASSERT_EQUAL(clonedGraph->getChildByName("T1")->getState(),YACS::DONE);
340   CPPUNIT_ASSERT_EQUAL(clonedGraph->getChildByName("T3")->getState(),YACS::DONE);
341   delete clonedGraph;
342   //
343   graph->edRemoveLink(o11,i31);
344   graph->edAddLink(o21,i31);//this link obliges that loops run at least 1 time : which is not the case
345   exe.RunW(graph);
346   CPPUNIT_ASSERT_EQUAL(loop->getState(),YACS::ERROR);
347   CPPUNIT_ASSERT_EQUAL(loop->getNbOfTurns(),0);
348   CPPUNIT_ASSERT_EQUAL(graph->getState(),YACS::FAILED);
349   CPPUNIT_ASSERT_EQUAL(n1->getState(),YACS::DONE);
350   CPPUNIT_ASSERT_EQUAL(n3->getState(),YACS::FAILED);
351   exe.RunW(graph);
352   CPPUNIT_ASSERT_EQUAL(loop->getState(),YACS::ERROR);
353   CPPUNIT_ASSERT_EQUAL(loop->getNbOfTurns(),0);
354   CPPUNIT_ASSERT_EQUAL(graph->getState(),YACS::FAILED);
355   CPPUNIT_ASSERT_EQUAL(n1->getState(),YACS::DONE);
356   CPPUNIT_ASSERT_EQUAL(n3->getState(),YACS::FAILED);
357   clonedGraph=(Bloc *)graph->clone(0);
358   exe2.RunW(clonedGraph);
359   CPPUNIT_ASSERT_EQUAL(((Loop *)clonedGraph->getChildByName("toto"))->getState(),YACS::ERROR);
360   CPPUNIT_ASSERT_EQUAL(((Loop *)clonedGraph->getChildByName("toto"))->getNbOfTurns(),0);
361   CPPUNIT_ASSERT_EQUAL(clonedGraph->getState(),YACS::FAILED);
362   CPPUNIT_ASSERT_EQUAL(clonedGraph->getChildByName("T1")->getState(),YACS::DONE);
363   CPPUNIT_ASSERT_EQUAL(clonedGraph->getChildByName("T3")->getState(),YACS::FAILED);
364   delete clonedGraph;
365   
366   //retrieves back state and retest
367   graph->edRemoveLink(o21,i31);
368   graph->edAddLink(o11,i31);
369   exe.RunW(graph);
370   CPPUNIT_ASSERT_EQUAL(loop->getState(),YACS::DONE);
371   CPPUNIT_ASSERT_EQUAL(loop->getNbOfTurns(),0);
372   CPPUNIT_ASSERT_EQUAL(graph->getState(),YACS::DONE);
373   CPPUNIT_ASSERT_EQUAL(n1->getState(),YACS::DONE);
374   CPPUNIT_ASSERT_EQUAL(n3->getState(),YACS::DONE);
375   exe.RunW(graph);
376   CPPUNIT_ASSERT_EQUAL(loop->getState(),YACS::DONE);
377   CPPUNIT_ASSERT_EQUAL(loop->getNbOfTurns(),0);
378   CPPUNIT_ASSERT_EQUAL(graph->getState(),YACS::DONE);
379   CPPUNIT_ASSERT_EQUAL(n1->getState(),YACS::DONE);
380   CPPUNIT_ASSERT_EQUAL(n3->getState(),YACS::DONE);
381   //Retrieves initial graph and test again
382   graph->edRemoveLink(o11,i31);
383   graph->edAddLink(o21,i31);
384   i11=n1->edAddInputPort("i11",tc_double);
385   i11->edInit(3.14);
386   i12=n1->edAddInputPort("i12",tc_double);
387   i12->edInit(2.78);
388   exe.RunW(graph);
389   CPPUNIT_ASSERT_DOUBLES_EQUAL( ((OutputToyPort*)graph->getOutputPort("T3.o1"))->get()->getDoubleValue(),10.12, DBL_PRECISION_COMPARE);
390   CPPUNIT_ASSERT_EQUAL(loop->getNbOfTurns(),2);
391   CPPUNIT_ASSERT_EQUAL(loop->getState(),YACS::DONE);
392   CPPUNIT_ASSERT_EQUAL(graph->getState(),YACS::DONE);
393   CPPUNIT_ASSERT_EQUAL(n1->getState(),YACS::DONE);
394   CPPUNIT_ASSERT_EQUAL(n3->getState(),YACS::DONE);
395   exe.RunW(graph);
396   CPPUNIT_ASSERT_DOUBLES_EQUAL( ((OutputToyPort*)graph->getOutputPort("T3.o1"))->get()->getDoubleValue(),10.12, DBL_PRECISION_COMPARE);
397   CPPUNIT_ASSERT_EQUAL(loop->getNbOfTurns(),2);
398   CPPUNIT_ASSERT_EQUAL(loop->getState(),YACS::DONE);
399   CPPUNIT_ASSERT_EQUAL(graph->getState(),YACS::DONE);
400   CPPUNIT_ASSERT_EQUAL(n1->getState(),YACS::DONE);
401   CPPUNIT_ASSERT_EQUAL(n3->getState(),YACS::DONE);
402   delete graph;
403 }
404
405 void EngineIntegrationTest::testForLoop4()
406 {
407   Bloc *graph=new Bloc("Graph");
408   ToyNode *n1=new ToyNode("T1"); graph->edAddChild(n1);
409   ForLoop *loop=new ForLoop("loop"); graph->edAddChild(loop); graph->edAddCFLink(n1,loop);
410   ToyNode *n2=new ToyNode("T2"); loop->edSetNode(n2);
411   n1->edAddInputPort("i11",Runtime::_tc_double)->edInit(3.);
412   n1->edAddInputPort("i12",Runtime::_tc_double)->edInit(4.);
413   n1->edAddInputPort("i13",Runtime::_tc_double)->edInit(5.);
414   OutputPort *o11=n1->edAddOutputPort("o11",Runtime::_tc_double);
415   InputPort *i21=n2->edAddInputPort("i21",Runtime::_tc_double);
416   n2->edAddInputPort("i22",Runtime::_tc_double)->edInit(2.);
417   OutputPort *o21=n2->edAddOutputPort("o21",Runtime::_tc_double);
418   graph->edAddLink(o11,i21);
419   graph->edAddLink(o21,i21);
420   graph->edAddLink(n1->edGetNbOfInputsOutputPort(),loop->edGetNbOfTimesInputPort());
421   Bloc *graph2=(Bloc *)graph->clone(0);
422   loop->edGetNbOfTimesInputPort()->edInit(0);
423   Executor exe;
424   exe.RunW(graph);
425   CPPUNIT_ASSERT_EQUAL(loop->getState(),YACS::DONE);
426   CPPUNIT_ASSERT_EQUAL(graph->getState(),YACS::DONE);
427   CPPUNIT_ASSERT_EQUAL(loop->getNbOfTurns(),3);
428   CPPUNIT_ASSERT_DOUBLES_EQUAL( ((OutputToyPort*)graph->getOutputPort("loop.T2.o21"))->get()->getDoubleValue(),18., DBL_PRECISION_COMPARE);
429   exe.RunW(graph);
430   CPPUNIT_ASSERT_EQUAL(loop->getState(),YACS::DONE);
431   CPPUNIT_ASSERT_EQUAL(graph->getState(),YACS::DONE);
432   CPPUNIT_ASSERT_EQUAL(loop->getNbOfTurns(),3);
433   CPPUNIT_ASSERT_DOUBLES_EQUAL( ((OutputToyPort*)graph->getOutputPort("loop.T2.o21"))->get()->getDoubleValue(),18., DBL_PRECISION_COMPARE);
434   Bloc *blocInt=new Bloc("blocInt");
435   graph->edRemoveChild(loop);
436   blocInt->edAddChild(loop);
437   graph->edAddChild(blocInt);
438   graph->edAddCFLink(n1,blocInt);
439   graph->edAddLink(o11,i21);
440   graph->edAddLink(n1->edGetNbOfInputsOutputPort(),loop->edGetNbOfTimesInputPort());
441   exe.RunW(graph);
442   CPPUNIT_ASSERT_EQUAL(loop->getState(),YACS::DONE);
443   CPPUNIT_ASSERT_EQUAL(graph->getState(),YACS::DONE);
444   CPPUNIT_ASSERT_EQUAL(3,loop->getNbOfTurns());
445   CPPUNIT_ASSERT_DOUBLES_EQUAL( ((OutputToyPort*)graph->getOutputPort("blocInt.loop.T2.o21"))->get()->getDoubleValue(),18., DBL_PRECISION_COMPARE);
446   exe.RunW(graph);
447   CPPUNIT_ASSERT_EQUAL(loop->getState(),YACS::DONE);
448   CPPUNIT_ASSERT_EQUAL(graph->getState(),YACS::DONE);
449   CPPUNIT_ASSERT_EQUAL(3,loop->getNbOfTurns());
450   CPPUNIT_ASSERT_DOUBLES_EQUAL( ((OutputToyPort*)graph->getOutputPort("blocInt.loop.T2.o21"))->get()->getDoubleValue(),18., DBL_PRECISION_COMPARE);
451   graph->edRemoveLink(n1->edGetNbOfInputsOutputPort(),loop->edGetNbOfTimesInputPort());
452   exe.RunW(graph);
453   CPPUNIT_ASSERT_EQUAL(loop->getState(),YACS::DONE);
454   CPPUNIT_ASSERT_EQUAL(graph->getState(),YACS::DONE);
455   CPPUNIT_ASSERT_EQUAL(0,loop->getNbOfTurns());
456   exe.RunW(graph);
457   CPPUNIT_ASSERT_EQUAL(loop->getState(),YACS::DONE);
458   CPPUNIT_ASSERT_EQUAL(graph->getState(),YACS::DONE);
459   CPPUNIT_ASSERT_EQUAL(0,loop->getNbOfTurns());
460   
461   exe.RunW(graph2);
462   ForLoop *loop2=(ForLoop *)graph2->getChildByName("loop");
463   CPPUNIT_ASSERT_EQUAL(loop2->getState(),YACS::DONE);
464   CPPUNIT_ASSERT_EQUAL(graph2->getState(),YACS::DONE);
465   CPPUNIT_ASSERT_EQUAL(loop2->getNbOfTurns(),3);
466   CPPUNIT_ASSERT_DOUBLES_EQUAL( ((OutputToyPort*)graph2->getOutputPort("loop.T2.o21"))->get()->getDoubleValue(),18., DBL_PRECISION_COMPARE);
467   exe.RunW(graph2);
468   CPPUNIT_ASSERT_EQUAL(loop2->getState(),YACS::DONE);
469   CPPUNIT_ASSERT_EQUAL(graph2->getState(),YACS::DONE);
470   CPPUNIT_ASSERT_EQUAL(loop2->getNbOfTurns(),3);
471   CPPUNIT_ASSERT_DOUBLES_EQUAL( ((OutputToyPort*)graph2->getOutputPort("loop.T2.o21"))->get()->getDoubleValue(),18., DBL_PRECISION_COMPARE);
472   Bloc *blocInt2=new Bloc("blocInt");
473   n1=(ToyNode *)graph2->getChildByName("T1");
474   graph2->edRemoveChild(loop2);
475   blocInt2->edAddChild(loop2);
476   graph2->edAddChild(blocInt2);
477   graph2->edAddCFLink(n1,blocInt2);
478   o11=graph2->getOutputPort("T1.o11");
479   i21=graph2->getInputPort("blocInt.loop.T2.i21");
480   graph2->edAddLink(o11,i21);
481   graph2->edAddLink(n1->edGetNbOfInputsOutputPort(),loop2->edGetNbOfTimesInputPort());
482   exe.RunW(graph2);
483   CPPUNIT_ASSERT_EQUAL(loop2->getState(),YACS::DONE);
484   CPPUNIT_ASSERT_EQUAL(graph2->getState(),YACS::DONE);
485   CPPUNIT_ASSERT_EQUAL(3,loop2->getNbOfTurns());
486   CPPUNIT_ASSERT_DOUBLES_EQUAL( ((OutputToyPort*)graph2->getOutputPort("blocInt.loop.T2.o21"))->get()->getDoubleValue(),18., DBL_PRECISION_COMPARE);
487   exe.RunW(graph2);
488   CPPUNIT_ASSERT_EQUAL(loop2->getState(),YACS::DONE);
489   CPPUNIT_ASSERT_EQUAL(graph2->getState(),YACS::DONE);
490   CPPUNIT_ASSERT_EQUAL(3,loop2->getNbOfTurns());
491   CPPUNIT_ASSERT_DOUBLES_EQUAL( ((OutputToyPort*)graph2->getOutputPort("blocInt.loop.T2.o21"))->get()->getDoubleValue(),18., DBL_PRECISION_COMPARE);
492   delete graph2;
493   delete graph;
494 }
495
496 //multi loop inclusion
497 void EngineIntegrationTest::testForLoop5()
498 {
499   Bloc *graph=new Bloc("Graph");
500   ToyNode *n1=new ToyNode("T1"); graph->edAddChild(n1);
501   Bloc *b1=new Bloc("b1"); graph->edAddChild(b1); graph->edAddCFLink(n1,b1);
502   ForLoop *loop2=new ForLoop("loop2"); b1->edAddChild(loop2);
503   Bloc *b3=new Bloc("b3"); loop2->edSetNode(b3);
504   ForLoop *loop4=new ForLoop("loop4"); b3->edAddChild(loop4);
505   Bloc *b5=new Bloc("b5"); loop4->edSetNode(b5);
506   ToyNode *n2=new ToyNode("T2"); b5->edAddChild(n2);
507   n1->edAddInputPort("i11",Runtime::_tc_double)->edInit(3.);
508   n1->edAddInputPort("i12",Runtime::_tc_double)->edInit(4.);
509   n1->edAddInputPort("i13",Runtime::_tc_double)->edInit(5.);
510   OutputPort *o11=n1->edAddOutputPort("o11",Runtime::_tc_double);
511   graph->edAddLink(n1->edGetNbOfInputsOutputPort(),loop2->edGetNbOfTimesInputPort());
512   loop4->edGetNbOfTimesInputPort()->edInit(2);
513   n2->edAddInputPort("i22",Runtime::_tc_double)->edInit(7.);
514   InputPort *i21=n2->edAddInputPort("i21",Runtime::_tc_double);
515   OutputPort *o21=n2->edAddOutputPort("o21",Runtime::_tc_double);
516   graph->edAddLink(o21,i21);
517   graph->edAddLink(o11,i21);
518   Executor exe;
519   exe.RunW(graph);
520   CPPUNIT_ASSERT_EQUAL(graph->getState(),YACS::DONE);
521   CPPUNIT_ASSERT_DOUBLES_EQUAL( ((OutputToyPort*)loop2->getOutputPort("b3.loop4.b5.T2.o21"))->get()->getDoubleValue(),54., DBL_PRECISION_COMPARE);
522   CPPUNIT_ASSERT_EQUAL(3,loop2->getNbOfTurns());
523   CPPUNIT_ASSERT_EQUAL(2,loop4->getNbOfTurns());
524   exe.RunW(graph);
525   CPPUNIT_ASSERT_EQUAL(graph->getState(),YACS::DONE);
526   CPPUNIT_ASSERT_DOUBLES_EQUAL( ((OutputToyPort*)loop2->getOutputPort("b3.loop4.b5.T2.o21"))->get()->getDoubleValue(),54., DBL_PRECISION_COMPARE);
527   CPPUNIT_ASSERT_EQUAL(3,loop2->getNbOfTurns());
528   CPPUNIT_ASSERT_EQUAL(2,loop4->getNbOfTurns());
529   delete graph;
530 }
531
532 void EngineIntegrationTest::testWhileLoop1()
533 {
534   TypeCode *tc_double    = Runtime::_tc_double;
535   TypeCode *tc_int       = Runtime::_tc_int;
536   ToyNode *n1=new ToyNode("T1");
537   InputPort *i11=n1->edAddInputPort("i11",tc_double);
538   i11->edInit(3.14);
539   InputPort *i12=n1->edAddInputPort("i12",tc_double);
540   i12->edInit(2.78);
541   InputPort *i13=n1->edAddInputPort("i13",tc_double);
542   i13->edInit(7.177);
543   OutputPort *o1=n1->edAddOutputPort("o1",tc_double);
544   LimitNode *l1=new LimitNode("L1");
545   OutputPort *ol1s=l1->getSwitchPort();
546   l1->setLimit(25.);
547   Bloc *graph=new Bloc("Graph");
548   //
549   Bloc *inLoop=new Bloc("inLoop");
550   ToyNode *n2=new ToyNode("T2");
551   InputPort *i21=n2->edAddInputPort("i1",tc_double);
552   InputPort *i22=n2->edAddInputPort("i2",tc_double);
553   OutputPort *o21=n2->edAddOutputPort("o1",tc_double);
554   i22->edInit(22.1006);
555   LimitNode *l2=new LimitNode("L2");
556   OutputPort *ol2s=l2->getSwitchPort();
557   l2->setLimit(100.);
558   inLoop->edAddChild(n2);
559   inLoop->edAddChild(l2);
560   WhileLoop *whileLoop=new WhileLoop("MyWhile");
561   whileLoop->edSetNode(inLoop);
562   inLoop->edAddCFLink(n2,l2);
563   inLoop->edAddLink(o21,l2->getEntry());
564   inLoop->edAddLink(l2->getCounterPort(),i21);
565   //
566   graph->edAddChild(n1);
567   graph->edAddChild(l1);
568   graph->edAddChild(whileLoop);
569   graph->edAddCFLink(n1,l1);
570   graph->edAddCFLink(l1,whileLoop);
571   graph->edAddCFLink(n1,whileLoop);
572   graph->edAddLink(l1->getSwitchPort(),whileLoop->edGetConditionPort());
573   graph->edAddLink(l2->getSwitchPort(),whileLoop->edGetConditionPort());
574   graph->edAddLink(o1,i21);
575   graph->edAddLink(o1,l1->getEntry());
576   Executor exe;
577   exe.RunW(graph);
578   CPPUNIT_ASSERT_DOUBLES_EQUAL( ((OutputLimitPort*)l2->getCounterPort())->get()->getDoubleValue(),207.0922, DBL_PRECISION_COMPARE);
579   CPPUNIT_ASSERT_EQUAL(whileLoop->getNbOfTurns(),3);
580   exe.RunW(graph);
581   CPPUNIT_ASSERT_DOUBLES_EQUAL( ((OutputLimitPort*)l2->getCounterPort())->get()->getDoubleValue(),207.0922, DBL_PRECISION_COMPARE);
582   CPPUNIT_ASSERT_EQUAL(whileLoop->getNbOfTurns(),3);
583   delete graph;
584 }
585
586 void EngineIntegrationTest::testSwitch()
587 {
588   RuntimeForEngineIntegrationTest::setRuntime();
589   Runtime *myRuntime = getRuntime();
590   TypeCode *tc_double    = Runtime::_tc_double;
591   TypeCode *tc_int       = Runtime::_tc_int;
592   Bloc *graph=new Bloc("Graph");
593
594   ToyNode *n1=new ToyNode("T1");
595   InputPort *i11=n1->edAddInputPort("i11",tc_double);
596   i11->edInit(17.);
597   OutputPort *o1=n1->edAddOutputPort("o1",tc_double);
598   graph->edAddChild(n1);
599   
600   Switch *mySwitch=new Switch("mySwitch");
601   graph->edAddChild(mySwitch);
602   graph->edAddCFLink(n1,mySwitch);
603
604   ToyNode *n2=new ToyNode("T2");
605   InputPort *i21=n2->edAddInputPort("i21",tc_double);
606   InputPort *i22=n2->edAddInputPort("i22",tc_double);
607   OutputPort *o21=n2->edAddOutputPort("o21",tc_double);
608   i22->edInit(1.);
609   mySwitch->edSetNode(0,n2);
610   graph->edAddLink(o1,i21);
611   graph->edAddLink(n1->edGetNbOfInputsOutputPort(),mySwitch->edGetConditionPort());
612   ToyNode *n3=new ToyNode("T3");
613   InputPort *i31=n3->edAddInputPort("i31",tc_double);
614   InputPort *i32=n3->edAddInputPort("i32",tc_double);
615   OutputPort *o31=n3->edAddOutputPort("o31",tc_double);
616   i32->edInit(2.);
617   mySwitch->edSetNode(1,n3);
618   graph->edAddLink(o1,i31);
619   try
620     {
621       graph->edAddLink(o31,i21);
622       CPPUNIT_ASSERT(0);
623     }
624   catch(Exception& e)
625     {
626       CPPUNIT_ASSERT(string(e.what())=="Switch::checkLinkPossibility : A link between 2 different cases of a same Switch requested -> Impossible");
627     }
628   ToyNode *n4=new ToyNode("T4");
629   InputPort *i41=n4->edAddInputPort("i41",tc_double);
630   InputPort *i42=n4->edAddInputPort("i42",tc_double);
631   OutputPort *o41=n4->edAddOutputPort("o41",tc_double);
632   i42->edInit(3.);
633   mySwitch->edSetNode(2,n4);
634   graph->edAddLink(o1,i41);
635   Executor exe;
636   exe.RunW(graph);
637   CPPUNIT_ASSERT_DOUBLES_EQUAL(((OutputToyPort*)o31)->get()->getDoubleValue(),19., DBL_PRECISION_COMPARE);
638   CPPUNIT_ASSERT_EQUAL(((OutputToyPort*)o21)->get(),(Any *)0);
639   CPPUNIT_ASSERT_EQUAL(((OutputToyPort*)o41)->get(),(Any *)0);
640   CPPUNIT_ASSERT_EQUAL(mySwitch->getState(),YACS::DONE);
641   CPPUNIT_ASSERT_EQUAL(graph->getState(),YACS::DONE);
642   InputPort *i12=n1->edAddInputPort("i12",tc_double);
643   i12->edInit(17.);
644   exe.RunW(graph);
645   CPPUNIT_ASSERT_DOUBLES_EQUAL(((OutputToyPort*)o41)->get()->getDoubleValue(),37., DBL_PRECISION_COMPARE);
646   CPPUNIT_ASSERT_EQUAL(((OutputToyPort*)o21)->get(),(Any *)0);
647   CPPUNIT_ASSERT_EQUAL(((OutputToyPort*)o31)->get(),(Any *)0);
648   CPPUNIT_ASSERT_EQUAL(mySwitch->getState(),YACS::DONE);
649   CPPUNIT_ASSERT_EQUAL(graph->getState(),YACS::DONE);
650   delete graph;
651 }
652
653 void EngineIntegrationTest::testSwitch2()
654 {
655   TypeCode *tc_double    = Runtime::_tc_double;
656   TypeCode *tc_int       = Runtime::_tc_int;
657   Bloc *graph=new Bloc("Graph");
658
659   ToyNode *n1=new ToyNode("T1");
660   InputPort *i11=n1->edAddInputPort("i11",tc_double);
661   i11->edInit(17.);
662   OutputPort *o1=n1->edAddOutputPort("o1",tc_double);
663   graph->edAddChild(n1);
664   
665   Switch *mySwitch=new Switch("mySwitch");
666   graph->edAddChild(mySwitch);
667   graph->edAddCFLink(n1,mySwitch);
668
669   ToyNode *n2=new ToyNode("T2");
670   InputPort *i21=n2->edAddInputPort("i21",tc_double);
671   InputPort *i22=n2->edAddInputPort("i22",tc_double);
672   OutputPort *o21=n2->edAddOutputPort("o21",tc_double);
673   i22->edInit(1.);
674   mySwitch->edSetNode(0,n2);
675   graph->edAddLink(o1,i21);
676   graph->edAddLink(n1->edGetNbOfInputsOutputPort(),mySwitch->edGetConditionPort());
677   ToyNode *n3=new ToyNode("T3");
678   InputPort *i31=n3->edAddInputPort("i31",tc_double);
679   InputPort *i32=n3->edAddInputPort("i32",tc_double);
680   OutputPort *o31=n3->edAddOutputPort("o31",tc_double);
681   i32->edInit(2.);
682   mySwitch->edSetNode(1,n3);
683   graph->edAddLink(o1,i31);
684   ToyNode *n4=new ToyNode("T4");
685   InputPort *i41=n4->edAddInputPort("i41",tc_double);
686   InputPort *i42=n4->edAddInputPort("i42",tc_double);
687   OutputPort *o41=n4->edAddOutputPort("o41",tc_double);
688   i42->edInit(3.);
689   mySwitch->edSetNode(2,n4);
690   graph->edAddLink(o1,i41);
691   LimitNode *l1=new LimitNode("L1");
692   l1->getEntry()->edInit(13.);
693   l1->setLimit(100.);
694   graph->edAddChild(l1);
695   //
696   Bloc *inLoop=new Bloc("inLoop");
697   ToyNode *nn2=new ToyNode("TT2");
698   inLoop->edAddChild(nn2);
699   InputPort *ii21=nn2->edAddInputPort("ii1",tc_double);
700   ii21->edInit(7.);
701   InputPort *ii22=nn2->edAddInputPort("ii2",tc_double);
702   OutputPort *oo21=nn2->edAddOutputPort("oo1",tc_double);
703   LimitNode *l2=new LimitNode("L2");
704   OutputPort *ool2s=l2->getSwitchPort();
705   l2->setLimit(100.);
706   inLoop->edAddChild(nn2);
707   inLoop->edAddChild(l2);
708   WhileLoop *whileLoop=new WhileLoop("MyWhile");
709   whileLoop->edSetNode(inLoop);
710   graph->edAddChild(whileLoop);
711   graph->edAddCFLink(l1,whileLoop);
712   graph->edAddLink(o21,ii22);
713   graph->edAddLink(o31,ii22);
714   graph->edAddLink(o41,ii22);
715   inLoop->edAddCFLink(nn2,l2);
716   graph->edAddCFLink(mySwitch,whileLoop);
717   inLoop->edAddLink(oo21,l2->getEntry());
718   inLoop->edAddLink(l2->getCounterPort(),ii21);
719   graph->edAddLink(l1->getSwitchPort(),whileLoop->edGetConditionPort());
720   graph->edAddLink(l2->getSwitchPort(),whileLoop->edGetConditionPort());
721   mySwitch->checkConsistency();
722   graph->edRemoveLink(o31,ii22);
723   try
724     {
725       mySwitch->checkConsistency();
726       CPPUNIT_ASSERT(0);
727     }
728   catch(Exception& e)
729     {
730       CPPUNIT_ASSERT(std::string(e.what())=="CollectorSwOutPort::checkCompletenessOfCases : For link to ii2 of node TT2 the cases of switch node named mySwitch do not define links for following cases ids :1 ");
731     }
732   graph->edRemoveLink(o41,ii22);
733   try
734     {
735       mySwitch->checkConsistency();
736       CPPUNIT_ASSERT(0);
737     }
738   catch(Exception& e)
739     {
740       CPPUNIT_ASSERT(std::string(e.what())=="CollectorSwOutPort::checkCompletenessOfCases : For link to ii2 of node TT2 the cases of switch node named mySwitch do not define links for following cases ids :1 2 ");
741     }
742   graph->edAddLink(o31,ii22);
743   graph->edAddLink(o41,ii22);
744   mySwitch->checkConsistency();
745   Executor exe;
746   DEBTRACE("Run graph");
747   exe.RunW(graph);
748   CPPUNIT_ASSERT_DOUBLES_EQUAL(((OutputToyPort*)l2->getCounterPort())->get()->getDoubleValue(),161., DBL_PRECISION_COMPARE);
749   CPPUNIT_ASSERT_EQUAL(3,whileLoop->getNbOfTurns());
750   CPPUNIT_ASSERT_EQUAL(whileLoop->getState(),YACS::DONE);
751   CPPUNIT_ASSERT_EQUAL(graph->getState(),YACS::DONE);
752   DEBTRACE("Run graph");
753   exe.RunW(graph);
754   CPPUNIT_ASSERT_DOUBLES_EQUAL(((OutputToyPort*)l2->getCounterPort())->get()->getDoubleValue(),161., DBL_PRECISION_COMPARE);
755   CPPUNIT_ASSERT_EQUAL(3,whileLoop->getNbOfTurns());
756   CPPUNIT_ASSERT_EQUAL(whileLoop->getState(),YACS::DONE);
757   CPPUNIT_ASSERT_EQUAL(graph->getState(),YACS::DONE);
758   //default
759   ToyNode *n5=new ToyNode("T5");
760   InputPort *i51=n5->edAddInputPort("i51",tc_double);
761   InputPort *i52=n5->edAddInputPort("i52",tc_double);
762   OutputPort *o51=n5->edAddOutputPort("o51",tc_double);
763   i52->edInit(4.);
764   mySwitch->edSetDefaultNode(n5);
765   graph->edAddLink(o1,i51);
766   try
767     {
768       mySwitch->checkConsistency();
769       CPPUNIT_ASSERT(0);
770     }
771   catch(Exception& e)
772     {
773       CPPUNIT_ASSERT(std::string(e.what())=="CollectorSwOutPort::checkCompletenessOfCases : For link to ii2 of node TT2 the cases of switch node named mySwitch do not define links for following cases ids :default ");
774     }
775   graph->edAddLink(o51,ii22);
776   mySwitch->checkConsistency();
777   DEBTRACE("Run graph");
778   exe.RunW(graph);
779   CPPUNIT_ASSERT_DOUBLES_EQUAL(((OutputToyPort*)l2->getCounterPort())->get()->getDoubleValue(),161., DBL_PRECISION_COMPARE);
780   CPPUNIT_ASSERT_EQUAL(3,whileLoop->getNbOfTurns());
781   CPPUNIT_ASSERT_EQUAL(whileLoop->getState(),YACS::DONE);
782   CPPUNIT_ASSERT_EQUAL(graph->getState(),YACS::DONE);
783   DEBTRACE("Run graph");
784   exe.RunW(graph);
785   CPPUNIT_ASSERT_DOUBLES_EQUAL(((OutputToyPort*)l2->getCounterPort())->get()->getDoubleValue(),161., DBL_PRECISION_COMPARE);
786   CPPUNIT_ASSERT_EQUAL(3,whileLoop->getNbOfTurns());
787   CPPUNIT_ASSERT_EQUAL(whileLoop->getState(),YACS::DONE);
788   CPPUNIT_ASSERT_EQUAL(graph->getState(),YACS::DONE);
789   try
790     {
791       mySwitch->edReleaseCase(4);
792       CPPUNIT_ASSERT(0);
793     }
794   catch(Exception& e)
795     {
796       CPPUNIT_ASSERT(std::string(e.what())=="Switch::edReleaseCase : the case # 4 is not set yet.");
797     }
798   mySwitch->edReleaseCase(1);
799   mySwitch->checkConsistency();
800   DEBTRACE("Run graph");
801   exe.RunW(graph);
802   CPPUNIT_ASSERT_DOUBLES_EQUAL(((OutputToyPort*)l2->getCounterPort())->get()->getDoubleValue(),175., DBL_PRECISION_COMPARE);
803   CPPUNIT_ASSERT_EQUAL(3,whileLoop->getNbOfTurns());
804   CPPUNIT_ASSERT_EQUAL(whileLoop->getState(),YACS::DONE);
805   CPPUNIT_ASSERT_EQUAL(graph->getState(),YACS::DONE);
806   DEBTRACE("Run graph");
807   exe.RunW(graph);
808   CPPUNIT_ASSERT_DOUBLES_EQUAL(((OutputToyPort*)l2->getCounterPort())->get()->getDoubleValue(),175., DBL_PRECISION_COMPARE);
809   CPPUNIT_ASSERT_EQUAL(3,whileLoop->getNbOfTurns());
810   CPPUNIT_ASSERT_EQUAL(whileLoop->getState(),YACS::DONE);
811   CPPUNIT_ASSERT_EQUAL(graph->getState(),YACS::DONE);
812   //now test when unexpected value is recieved and no default node specifies
813   mySwitch->edReleaseDefaultNode();
814   mySwitch->checkConsistency();
815   DEBTRACE("Run graph");
816   exe.RunW(graph);
817   CPPUNIT_ASSERT_EQUAL(whileLoop->getState(),YACS::FAILED);
818   CPPUNIT_ASSERT_EQUAL(graph->getState(),YACS::FAILED);
819   CPPUNIT_ASSERT_EQUAL(mySwitch->getState(),YACS::ERROR);
820   DEBTRACE("Run graph");
821   exe.RunW(graph);
822   CPPUNIT_ASSERT_EQUAL(whileLoop->getState(),YACS::FAILED);
823   CPPUNIT_ASSERT_EQUAL(graph->getState(),YACS::FAILED);
824   CPPUNIT_ASSERT_EQUAL(mySwitch->getState(),YACS::ERROR);
825   //retrieving back state
826   mySwitch->edSetDefaultNode(n5);
827   graph->edAddLink(o1,i51);
828   try
829     {
830       mySwitch->checkConsistency();
831       CPPUNIT_ASSERT(0);
832     }
833   catch(Exception& e)
834     {
835       CPPUNIT_ASSERT(std::string(e.what())=="CollectorSwOutPort::checkCompletenessOfCases : For link to ii2 of node TT2 the cases of switch node named mySwitch do not define links for following cases ids :default ");
836     }
837   graph->edAddLink(o51,ii22);
838   mySwitch->checkConsistency();
839   DEBTRACE("Run graph");
840   exe.RunW(graph);
841   CPPUNIT_ASSERT_DOUBLES_EQUAL(((OutputToyPort*)l2->getCounterPort())->get()->getDoubleValue(),175., DBL_PRECISION_COMPARE);
842   CPPUNIT_ASSERT_EQUAL(3,whileLoop->getNbOfTurns());
843   CPPUNIT_ASSERT_EQUAL(whileLoop->getState(),YACS::DONE);
844   CPPUNIT_ASSERT_EQUAL(graph->getState(),YACS::DONE);
845   DEBTRACE("Run graph");
846   exe.RunW(graph);
847   CPPUNIT_ASSERT_DOUBLES_EQUAL(((OutputToyPort*)l2->getCounterPort())->get()->getDoubleValue(),175., DBL_PRECISION_COMPARE);
848   CPPUNIT_ASSERT_EQUAL(3,whileLoop->getNbOfTurns());
849   CPPUNIT_ASSERT_EQUAL(whileLoop->getState(),YACS::DONE);
850   CPPUNIT_ASSERT_EQUAL(graph->getState(),YACS::DONE);
851   //and finally retrieving initial state
852   mySwitch->edSetNode(1,n3);
853   graph->edAddLink(o1,i31);
854   graph->edAddLink(o31,ii22);
855   DEBTRACE("Run graph");
856   exe.RunW(graph);
857   CPPUNIT_ASSERT_DOUBLES_EQUAL(((OutputToyPort*)l2->getCounterPort())->get()->getDoubleValue(),161., DBL_PRECISION_COMPARE);
858   CPPUNIT_ASSERT_EQUAL(3,whileLoop->getNbOfTurns());
859   CPPUNIT_ASSERT_EQUAL(whileLoop->getState(),YACS::DONE);
860   CPPUNIT_ASSERT_EQUAL(graph->getState(),YACS::DONE);
861   DEBTRACE("Run graph");
862   exe.RunW(graph);
863   CPPUNIT_ASSERT_DOUBLES_EQUAL(((OutputToyPort*)l2->getCounterPort())->get()->getDoubleValue(),161., DBL_PRECISION_COMPARE);
864   CPPUNIT_ASSERT_EQUAL(3,whileLoop->getNbOfTurns());
865   CPPUNIT_ASSERT_EQUAL(whileLoop->getState(),YACS::DONE);
866   CPPUNIT_ASSERT_EQUAL(graph->getState(),YACS::DONE);
867   Bloc *clonedGraph=(Bloc *)graph->clone(0);
868   delete graph;
869   Executor exe2;
870   exe2.RunW(clonedGraph);
871   CPPUNIT_ASSERT_DOUBLES_EQUAL(((OutputToyPort*)clonedGraph->getOutPort("MyWhile.inLoop.L2.SwitchPort2"))->get()->getDoubleValue(),161., DBL_PRECISION_COMPARE);
872   CPPUNIT_ASSERT_EQUAL(3,((WhileLoop *)clonedGraph->getChildByName("MyWhile"))->getNbOfTurns());
873   CPPUNIT_ASSERT_EQUAL(((WhileLoop *)clonedGraph->getChildByName("MyWhile"))->getState(),YACS::DONE);
874   CPPUNIT_ASSERT_EQUAL(clonedGraph->getState(),YACS::DONE);
875   delete clonedGraph;
876 }
877
878 /**
879  * multi switch inclusion - link update
880  */
881 void EngineIntegrationTest::testSwitch3()
882 {
883   Bloc *graph=new Bloc("Graph");
884   Switch *mySwitch1=new Switch("mySwitch1");
885   graph->edAddChild(mySwitch1);
886   Switch *mySwitch2=new Switch("mySwitch2");
887   mySwitch1->edSetNode(2,mySwitch2);
888   ToyNode *n1=new ToyNode("T1"); Bloc *blocForT1=new Bloc("blocForT1"); blocForT1->edAddChild(n1);
889   ToyNode *n2=new ToyNode("T2"); Bloc *blocForT2=new Bloc("blocForT2"); blocForT2->edAddChild(n2); mySwitch1->edSetNode(3,blocForT2);graph->edAddChild(blocForT1); n2->edAddInputPort("i22",Runtime::_tc_double)->edInit(2.);
890   ToyNode *n3=new ToyNode("T3"); mySwitch2->edSetNode(2,n3); n3->edAddInputPort("i32",Runtime::_tc_double)->edInit(3.);
891   ToyNode *n4=new ToyNode("T4"); Bloc *blocForT4=new Bloc("blocForT4"); blocForT4->edAddChild(n4); mySwitch2->edSetNode(5,blocForT4); n4->edAddInputPort("i42",Runtime::_tc_double)->edInit(4.);
892   ToyNode *n5=new ToyNode("T5"); mySwitch2->edSetNode(8,n5); n5->edAddInputPort("i52",Runtime::_tc_double)->edInit(5.);
893   ToyNode *n6=new ToyNode("T6"); graph->edAddChild(n6);
894   graph->edAddCFLink(blocForT1,mySwitch1);
895   graph->edAddCFLink(mySwitch1,n6);
896   mySwitch2->getInputPort("select")->edInit(5);
897   mySwitch1->getInputPort("select")->edInit(2);
898   InputPort *i11=n1->edAddInputPort("i11",Runtime::_tc_double); OutputPort *o11=n1->edAddOutputPort("o11",Runtime::_tc_double);
899   InputPort *i21=n2->edAddInputPort("i21",Runtime::_tc_double); OutputPort *o21=n2->edAddOutputPort("o21",Runtime::_tc_double);
900   InputPort *i31=n3->edAddInputPort("i31",Runtime::_tc_double); OutputPort *o31=n3->edAddOutputPort("o31",Runtime::_tc_double);
901   InputPort *i41=n4->edAddInputPort("i41",Runtime::_tc_double); OutputPort *o41=n4->edAddOutputPort("o41",Runtime::_tc_double);
902   InputPort *i51=n5->edAddInputPort("i51",Runtime::_tc_double); OutputPort *o51=n5->edAddOutputPort("o51",Runtime::_tc_double);
903   InputPort *i61=n6->edAddInputPort("i61",Runtime::_tc_double); OutputPort *o61=n6->edAddOutputPort("o61",Runtime::_tc_double);
904   i11->edInit(17.);
905   graph->edAddLink(o11,i21); graph->edAddLink(o11,i31); graph->edAddLink(o11,i41); graph->edAddLink(o11,i51);
906   graph->edAddLink(o21,i61);
907   graph->edAddLink(o31,i61);
908   graph->edAddLink(o41,i61);
909   graph->edAddLink(o51,i61);
910   mySwitch1->checkConsistency();
911   mySwitch2->checkConsistency();
912   CPPUNIT_ASSERT_EQUAL(1,n6->getInGate()->getNumberOfBackLinks());
913   CPPUNIT_ASSERT_EQUAL(1,i61->edGetNumberOfLinks());// <-- important
914   CPPUNIT_ASSERT_EQUAL(4,o11->edGetNumberOfOutLinks()); 
915   CPPUNIT_ASSERT_EQUAL(1,i21->edGetNumberOfLinks());
916   CPPUNIT_ASSERT_EQUAL(1,i31->edGetNumberOfLinks());
917   graph->edRemoveLink(o21,i61);
918   CPPUNIT_ASSERT_EQUAL(1,i61->edGetNumberOfLinks());// <-- important
919   CPPUNIT_ASSERT_EQUAL(0,o21->edGetNumberOfOutLinks());
920   CPPUNIT_ASSERT_EQUAL(1,i31->edGetNumberOfLinks());
921   graph->edAddLink(o21,i61);
922   graph->edRemoveLink(o31,i61);
923   graph->edRemoveLink(o41,i61);
924   graph->edRemoveLink(o51,i61);
925   CPPUNIT_ASSERT_EQUAL(1,i61->edGetNumberOfLinks());// <-- important
926   graph->edRemoveLink(o21,i61);
927   CPPUNIT_ASSERT_EQUAL(0,i61->edGetNumberOfLinks());// <-- important
928   graph->edAddLink(o21,i61);
929   CPPUNIT_ASSERT_EQUAL(1,i61->edGetNumberOfLinks());
930   graph->edAddLink(o41,i61);
931   CPPUNIT_ASSERT_EQUAL(1,i61->edGetNumberOfLinks());
932   try
933     {
934       mySwitch2->checkConsistency();
935       CPPUNIT_ASSERT(0);
936     }
937   catch(Exception& e)
938     {
939       CPPUNIT_ASSERT(std::string(e.what())=="CollectorSwOutPort::checkCompletenessOfCases : For link to i61 of node T6 the cases of switch node named mySwitch2 do not define links for following cases ids :2 8 ");
940     }
941   graph->edAddLink(o31,i61);
942   graph->edAddLink(o51,i61);
943   mySwitch2->checkConsistency();
944   CPPUNIT_ASSERT_EQUAL(1,i61->edGetNumberOfLinks());
945   Executor exe;
946   exe.RunW(graph);
947   CPPUNIT_ASSERT_DOUBLES_EQUAL( ((OutputToyPort*)graph->getOutputPort("T6.o61"))->get()->getDoubleValue(),21., DBL_PRECISION_COMPARE);
948   exe.RunW(graph);
949   CPPUNIT_ASSERT_DOUBLES_EQUAL( ((OutputToyPort*)graph->getOutputPort("T6.o61"))->get()->getDoubleValue(),21., DBL_PRECISION_COMPARE);
950   mySwitch1->getInputPort("select")->edInit(3);
951   exe.RunW(graph);
952   CPPUNIT_ASSERT_DOUBLES_EQUAL( ((OutputToyPort*)graph->getOutputPort("T6.o61"))->get()->getDoubleValue(),19., DBL_PRECISION_COMPARE);
953   exe.RunW(graph);
954   CPPUNIT_ASSERT_DOUBLES_EQUAL( ((OutputToyPort*)graph->getOutputPort("T6.o61"))->get()->getDoubleValue(),19., DBL_PRECISION_COMPARE);
955   delete graph;
956 }
957
958 void EngineIntegrationTest::testWhileLoop2()//Test of 0 turn of loop
959 {
960   //first test without any link to condition port on start of loop that is to say WhileLoop is considered has while and NOT dowhile.
961   TypeCode *tc_double    = Runtime::_tc_double;
962   TypeCode *tc_int       = Runtime::_tc_int;
963   ToyNode *n1=new ToyNode("T1");
964   InputPort *i11=n1->edAddInputPort("i11",tc_double);
965   i11->edInit(3.14);
966   InputPort *i12=n1->edAddInputPort("i12",tc_double);
967   i12->edInit(2.78);
968   OutputPort *o11=n1->edAddOutputPort("o1",tc_double);
969   ToyNode *n2=new ToyNode("T2");
970   InputPort *i21=n2->edAddInputPort("i1",tc_double);
971   InputPort *i22=n2->edAddInputPort("i2",tc_double);
972   i22->edInit(22.1);
973   OutputPort *o21=n2->edAddOutputPort("o1",tc_double);
974   ToyNode *n3=new ToyNode("T3");
975   InputPort *i31=n3->edAddInputPort("i1",tc_double);
976   OutputPort *o31=n3->edAddOutputPort("o1",tc_double);
977   LimitNode *l2=new LimitNode("L2");
978   OutputPort *ol2s=l2->getSwitchPort();
979   l2->setLimit(100.);
980   Bloc *titi=new Bloc("titi");
981   titi->edAddChild(n2);
982   titi->edAddChild(l2);
983   WhileLoop *loop=new WhileLoop("toto");
984   loop->edSetNode(titi);
985   Bloc *graph=new Bloc("Graph");
986   graph->edAddChild(loop);
987   graph->edAddChild(n1);
988   graph->edAddChild(n3);
989   graph->edAddCFLink(n1,loop);
990   graph->edAddCFLink(loop,n3);
991   titi->edAddCFLink(n2,l2);
992   graph->edAddLink(o11,i21);
993   graph->edAddLink(o21,l2->getEntry());
994   graph->edAddLink(ol2s,loop->edGetConditionPort());
995   graph->edAddLink(o21,i21);
996   graph->edAddLink(o21,i31);
997   Executor exe;
998   DEBTRACE("Run graph");
999   exe.RunW(graph);
1000   DEBTRACE("After Run graph");
1001   CPPUNIT_ASSERT_DOUBLES_EQUAL( ((OutputToyPort*)graph->getOutputPort("T3.o1"))->get()->getDoubleValue(),72.22, DBL_PRECISION_COMPARE);
1002   CPPUNIT_ASSERT_EQUAL(loop->getNbOfTurns(),3);
1003   CPPUNIT_ASSERT_EQUAL(loop->getState(),YACS::DONE);
1004   CPPUNIT_ASSERT_EQUAL(graph->getState(),YACS::DONE);
1005   CPPUNIT_ASSERT_EQUAL(n1->getState(),YACS::DONE);
1006   CPPUNIT_ASSERT_EQUAL(n2->getState(),YACS::DONE);
1007   CPPUNIT_ASSERT_EQUAL(n3->getState(),YACS::DONE);
1008   DEBTRACE("Run graph");
1009   exe.RunW(graph);
1010   CPPUNIT_ASSERT_DOUBLES_EQUAL( ((OutputToyPort*)graph->getOutputPort("T3.o1"))->get()->getDoubleValue(), 72.22, DBL_PRECISION_COMPARE);
1011   CPPUNIT_ASSERT_EQUAL(loop->getNbOfTurns(),3);
1012   CPPUNIT_ASSERT_EQUAL(loop->getState(),YACS::DONE);
1013   CPPUNIT_ASSERT_EQUAL(graph->getState(),YACS::DONE);
1014   CPPUNIT_ASSERT_EQUAL(n1->getState(),YACS::DONE);
1015   CPPUNIT_ASSERT_EQUAL(n2->getState(),YACS::DONE);
1016   CPPUNIT_ASSERT_EQUAL(n3->getState(),YACS::DONE);
1017   //Link on conditionPort of while same behaviour as ahead
1018   LimitNode *l1=new LimitNode("L1");
1019   graph->edAddChild(l1);
1020   OutputPort *ol1s=l1->getSwitchPort();
1021   l1->setLimit(100.);
1022   l1->getEntry()->edInit(12.);
1023   graph->edAddCFLink(l1,loop);
1024   graph->edAddLink(ol1s,loop->edGetConditionPort());
1025   DEBTRACE("Run graph");
1026   exe.RunW(graph);
1027   CPPUNIT_ASSERT_DOUBLES_EQUAL( ((OutputToyPort*)graph->getOutputPort("T3.o1"))->get()->getDoubleValue(),72.22, DBL_PRECISION_COMPARE);
1028   CPPUNIT_ASSERT_EQUAL(loop->getNbOfTurns(),3);
1029   CPPUNIT_ASSERT_EQUAL(loop->getState(),YACS::DONE);
1030   CPPUNIT_ASSERT_EQUAL(graph->getState(),YACS::DONE);
1031   CPPUNIT_ASSERT_EQUAL(n1->getState(),YACS::DONE);
1032   CPPUNIT_ASSERT_EQUAL(n2->getState(),YACS::DONE);
1033   CPPUNIT_ASSERT_EQUAL(n3->getState(),YACS::DONE);
1034   DEBTRACE("Run graph");
1035   exe.RunW(graph);
1036   CPPUNIT_ASSERT_DOUBLES_EQUAL( ((OutputToyPort*)graph->getOutputPort("T3.o1"))->get()->getDoubleValue(),72.22, DBL_PRECISION_COMPARE);
1037   CPPUNIT_ASSERT_EQUAL(loop->getNbOfTurns(),3);
1038   CPPUNIT_ASSERT_EQUAL(loop->getState(),YACS::DONE);
1039   CPPUNIT_ASSERT_EQUAL(graph->getState(),YACS::DONE);
1040   CPPUNIT_ASSERT_EQUAL(n1->getState(),YACS::DONE);
1041   CPPUNIT_ASSERT_EQUAL(n2->getState(),YACS::DONE);
1042   CPPUNIT_ASSERT_EQUAL(n3->getState(),YACS::DONE);
1043   //Now no turn in while loop...
1044   l1->getEntry()->edInit(120.);
1045   DEBTRACE("Run graph");
1046   exe.RunW(graph);
1047   CPPUNIT_ASSERT_EQUAL(loop->getState(),YACS::ERROR);
1048   CPPUNIT_ASSERT_EQUAL(loop->getNbOfTurns(),0);
1049   CPPUNIT_ASSERT_EQUAL(graph->getState(),YACS::FAILED);
1050   CPPUNIT_ASSERT_EQUAL(n1->getState(),YACS::DONE);
1051   CPPUNIT_ASSERT_EQUAL(l1->getState(),YACS::DONE);
1052   CPPUNIT_ASSERT_EQUAL(n3->getState(),YACS::FAILED);
1053   DEBTRACE("Run graph");
1054   exe.RunW(graph);
1055   CPPUNIT_ASSERT_EQUAL(loop->getState(),YACS::ERROR);
1056   CPPUNIT_ASSERT_EQUAL(loop->getNbOfTurns(),0);
1057   CPPUNIT_ASSERT_EQUAL(graph->getState(),YACS::FAILED);
1058   CPPUNIT_ASSERT_EQUAL(n1->getState(),YACS::DONE);
1059   CPPUNIT_ASSERT_EQUAL(l1->getState(),YACS::DONE);
1060   CPPUNIT_ASSERT_EQUAL(n3->getState(),YACS::FAILED);
1061   //like before
1062   l1->getEntry()->edInit(12.);
1063   DEBTRACE("Run graph");
1064   exe.RunW(graph);
1065   CPPUNIT_ASSERT_DOUBLES_EQUAL( ((OutputToyPort*)graph->getOutputPort("T3.o1"))->get()->getDoubleValue(),72.22, DBL_PRECISION_COMPARE);
1066   CPPUNIT_ASSERT_EQUAL(loop->getNbOfTurns(),3);
1067   CPPUNIT_ASSERT_EQUAL(loop->getState(),YACS::DONE);
1068   CPPUNIT_ASSERT_EQUAL(graph->getState(),YACS::DONE);
1069   CPPUNIT_ASSERT_EQUAL(n1->getState(),YACS::DONE);
1070   CPPUNIT_ASSERT_EQUAL(n2->getState(),YACS::DONE);
1071   CPPUNIT_ASSERT_EQUAL(n3->getState(),YACS::DONE);
1072   DEBTRACE("Run graph");
1073   exe.RunW(graph);
1074   CPPUNIT_ASSERT_DOUBLES_EQUAL( ((OutputToyPort*)graph->getOutputPort("T3.o1"))->get()->getDoubleValue(),72.22, DBL_PRECISION_COMPARE);
1075   CPPUNIT_ASSERT_EQUAL(loop->getNbOfTurns(),3);
1076   CPPUNIT_ASSERT_EQUAL(loop->getState(),YACS::DONE);
1077   CPPUNIT_ASSERT_EQUAL(graph->getState(),YACS::DONE);
1078   CPPUNIT_ASSERT_EQUAL(n1->getState(),YACS::DONE);
1079   CPPUNIT_ASSERT_EQUAL(n2->getState(),YACS::DONE);
1080   CPPUNIT_ASSERT_EQUAL(n3->getState(),YACS::DONE);
1081   //now 0 turn of loop but no back dependancies
1082   l1->getEntry()->edInit(125.);
1083   graph->edRemoveLink(o21,i31);
1084   graph->edAddLink(o11,i31);//this
1085   DEBTRACE("Run graph");
1086   exe.RunW(graph);
1087   CPPUNIT_ASSERT_DOUBLES_EQUAL( ((OutputToyPort*)graph->getOutputPort("T3.o1"))->get()->getDoubleValue(),5.92, DBL_PRECISION_COMPARE);
1088   CPPUNIT_ASSERT_EQUAL(loop->getNbOfTurns(),0);
1089   CPPUNIT_ASSERT_EQUAL(loop->getState(),YACS::DONE);
1090   CPPUNIT_ASSERT_EQUAL(graph->getState(),YACS::DONE);
1091   CPPUNIT_ASSERT_EQUAL(n1->getState(),YACS::DONE);
1092   CPPUNIT_ASSERT_EQUAL(n3->getState(),YACS::DONE);
1093   DEBTRACE("Run graph");
1094   exe.RunW(graph);
1095   CPPUNIT_ASSERT_DOUBLES_EQUAL( ((OutputToyPort*)graph->getOutputPort("T3.o1"))->get()->getDoubleValue(),5.92, DBL_PRECISION_COMPARE);
1096   CPPUNIT_ASSERT_EQUAL(loop->getNbOfTurns(),0);
1097   CPPUNIT_ASSERT_EQUAL(loop->getState(),YACS::DONE);
1098   CPPUNIT_ASSERT_EQUAL(graph->getState(),YACS::DONE);
1099   CPPUNIT_ASSERT_EQUAL(n1->getState(),YACS::DONE);
1100   CPPUNIT_ASSERT_EQUAL(n3->getState(),YACS::DONE);
1101   //
1102   graph->edRemoveChild(l1);
1103   delete l1;
1104   graph->getInputPort("toto.condition")->edInit(false);
1105   DEBTRACE("Run graph");
1106   exe.RunW(graph);
1107   CPPUNIT_ASSERT_DOUBLES_EQUAL( ((OutputToyPort*)graph->getOutputPort("T3.o1"))->get()->getDoubleValue(),5.92, DBL_PRECISION_COMPARE);
1108   CPPUNIT_ASSERT_EQUAL(loop->getNbOfTurns(),0);
1109   CPPUNIT_ASSERT_EQUAL(loop->getState(),YACS::DONE);
1110   CPPUNIT_ASSERT_EQUAL(graph->getState(),YACS::DONE);
1111   CPPUNIT_ASSERT_EQUAL(n1->getState(),YACS::DONE);
1112   CPPUNIT_ASSERT_EQUAL(n3->getState(),YACS::DONE);
1113   DEBTRACE("Run graph");
1114   exe.RunW(graph);
1115   CPPUNIT_ASSERT_DOUBLES_EQUAL( ((OutputToyPort*)graph->getOutputPort("T3.o1"))->get()->getDoubleValue(),5.92, DBL_PRECISION_COMPARE);
1116   CPPUNIT_ASSERT_EQUAL(loop->getNbOfTurns(),0);
1117   CPPUNIT_ASSERT_EQUAL(loop->getState(),YACS::DONE);
1118   CPPUNIT_ASSERT_EQUAL(graph->getState(),YACS::DONE);
1119   CPPUNIT_ASSERT_EQUAL(n1->getState(),YACS::DONE);
1120   CPPUNIT_ASSERT_EQUAL(n3->getState(),YACS::DONE);
1121   //
1122   graph->getInputPort("toto.condition")->edInit(true);
1123   DEBTRACE("Run graph");
1124   exe.RunW(graph);
1125   CPPUNIT_ASSERT_DOUBLES_EQUAL( ((OutputToyPort*)graph->getOutputPort("T3.o1"))->get()->getDoubleValue(),5.92, DBL_PRECISION_COMPARE);
1126   CPPUNIT_ASSERT_DOUBLES_EQUAL( ((OutputToyPort*)l2->getCounterPort())->get()->getDoubleValue(),150.36, DBL_PRECISION_COMPARE);
1127   CPPUNIT_ASSERT_EQUAL(loop->getNbOfTurns(),3);
1128   CPPUNIT_ASSERT_EQUAL(loop->getState(),YACS::DONE);
1129   CPPUNIT_ASSERT_EQUAL(graph->getState(),YACS::DONE);
1130   CPPUNIT_ASSERT_EQUAL(n1->getState(),YACS::DONE);
1131   CPPUNIT_ASSERT_EQUAL(n3->getState(),YACS::DONE);
1132   delete graph;
1133 }
1134
1135 void EngineIntegrationTest::testEdInitOnLoops()
1136 {
1137   ForLoop *loop=new ForLoop("totoloop");
1138   Bloc *titi=new Bloc("titi");
1139   ToyNode *n2=new ToyNode("T2");
1140   titi->edAddChild(n2);
1141   loop->edSetNode(titi);
1142   InputPort *i21=n2->edAddInputPort("i1",Runtime::_tc_double);
1143   InputPort *i22=n2->edAddInputPort("i2",Runtime::_tc_double);
1144   i21->edInit(2.1);
1145   i22->edInit(4.3);
1146   OutputPort *o21=n2->edAddOutputPort("o1",Runtime::_tc_double);
1147   titi->edAddLink(o21,i21);
1148   loop->edGetNbOfTimesInputPort()->edInit(4);
1149   Executor exe;
1150   exe.RunW(loop);
1151   CPPUNIT_ASSERT_DOUBLES_EQUAL( ((OutputToyPort*)loop->getOutputPort("titi.T2.o1"))->get()->getDoubleValue(),19.3, DBL_PRECISION_COMPARE);
1152   CPPUNIT_ASSERT_EQUAL(loop->getNbOfTurns(),4);
1153   CPPUNIT_ASSERT_EQUAL(loop->getState(),YACS::DONE);
1154   CPPUNIT_ASSERT_EQUAL(n2->getState(),YACS::DONE);
1155   exe.RunW(loop);
1156   CPPUNIT_ASSERT_DOUBLES_EQUAL( ((OutputToyPort*)loop->getOutputPort("titi.T2.o1"))->get()->getDoubleValue(),19.3, DBL_PRECISION_COMPARE);
1157   CPPUNIT_ASSERT_EQUAL(loop->getNbOfTurns(),4);
1158   CPPUNIT_ASSERT_EQUAL(loop->getState(),YACS::DONE);
1159   CPPUNIT_ASSERT_EQUAL(n2->getState(),YACS::DONE);
1160   loop->edGetNbOfTimesInputPort()->edInit(5);
1161   exe.RunW(loop);
1162   CPPUNIT_ASSERT_DOUBLES_EQUAL( ((OutputToyPort*)loop->getOutputPort("titi.T2.o1"))->get()->getDoubleValue(),23.6, DBL_PRECISION_COMPARE);
1163   CPPUNIT_ASSERT_EQUAL(loop->getNbOfTurns(),5);
1164   CPPUNIT_ASSERT_EQUAL(loop->getState(),YACS::DONE);
1165   CPPUNIT_ASSERT_EQUAL(n2->getState(),YACS::DONE);
1166   loop->edGetNbOfTimesInputPort()->edInit(0);
1167   exe.RunW(loop);
1168   CPPUNIT_ASSERT_EQUAL(loop->getNbOfTurns(),0);
1169   CPPUNIT_ASSERT_EQUAL(loop->getState(),YACS::DONE);
1170   exe.RunW(loop);
1171   CPPUNIT_ASSERT_EQUAL(loop->getNbOfTurns(),0);
1172   CPPUNIT_ASSERT_EQUAL(loop->getState(),YACS::DONE);
1173   delete loop;
1174 }
1175
1176 /**
1177  * This test peers at link deletion forwarding for switch
1178  */
1179 void EngineIntegrationTest::testLinkUpdate1()
1180 {
1181   Bloc *graph=new Bloc("Graph");
1182
1183   ToyNode *n1=new ToyNode("T1");
1184   InputPort *i11=n1->edAddInputPort("i11",Runtime::_tc_double);
1185   i11->edInit(17.);
1186   OutputPort *o1=n1->edAddOutputPort("o1",Runtime::_tc_double);
1187   graph->edAddChild(n1);
1188   
1189   Switch *mySwitch=new Switch("mySwitch");
1190   graph->edAddChild(mySwitch);
1191   graph->edAddCFLink(n1,mySwitch);
1192
1193   ToyNode *n2=new ToyNode("T2");
1194   InputPort *i21=n2->edAddInputPort("i21",Runtime::_tc_double);
1195   InputPort *i22=n2->edAddInputPort("i22",Runtime::_tc_double);
1196   OutputPort *o21=n2->edAddOutputPort("o21",Runtime::_tc_double);
1197   OutputPort *o22=n2->edAddOutputPort("o22",Runtime::_tc_double);
1198   i22->edInit(1.);
1199   mySwitch->edSetNode(0,n2);
1200   graph->edAddLink(o1,i21);
1201   graph->edAddLink(n1->edGetNbOfInputsOutputPort(),mySwitch->edGetConditionPort());
1202   ToyNode *n3=new ToyNode("T3");
1203   Bloc *Bn3=new Bloc("Bn3");
1204   Bn3->edAddChild(n3);
1205   InputPort *i31=n3->edAddInputPort("i31",Runtime::_tc_double);
1206   InputPort *i32=n3->edAddInputPort("i32",Runtime::_tc_double);
1207   OutputPort *o31=n3->edAddOutputPort("o31",Runtime::_tc_double);
1208   OutputPort *o32=n3->edAddOutputPort("o32",Runtime::_tc_double);
1209   i32->edInit(2.);
1210   mySwitch->edSetNode(1,Bn3);
1211   graph->edAddLink(o1,i31);
1212   //
1213   ToyNode *n4=new ToyNode("T4");
1214   InputPort *i41=n4->edAddInputPort("i41",Runtime::_tc_double);
1215   InputPort *i42=n4->edAddInputPort("i42",Runtime::_tc_double);
1216   OutputPort *o41=n4->edAddOutputPort("o41",Runtime::_tc_double);
1217   i42->edInit(3.14);
1218   graph->edAddChild(n4);
1219   graph->edAddCFLink(mySwitch,n4);
1220   graph->edAddLink(o21,i41);
1221   graph->edAddLink(o31,i41);
1222   mySwitch->checkConsistency();
1223   CPPUNIT_ASSERT_EQUAL(1,o21->edGetNumberOfOutLinks());
1224   CPPUNIT_ASSERT_EQUAL(1,o31->edGetNumberOfOutLinks());
1225   CPPUNIT_ASSERT_EQUAL(1,i41->edGetNumberOfLinks());// <-- important
1226   graph->edRemoveLink(o21,i41);
1227   CPPUNIT_ASSERT_EQUAL(0,o21->edGetNumberOfOutLinks());
1228   CPPUNIT_ASSERT_EQUAL(1,o31->edGetNumberOfOutLinks());
1229   CPPUNIT_ASSERT_EQUAL(1,i41->edGetNumberOfLinks());// <-- important
1230   graph->edRemoveLink(o31,i41);//normally implies collector inputport deletion
1231   CPPUNIT_ASSERT_EQUAL(0,o21->edGetNumberOfOutLinks());
1232   CPPUNIT_ASSERT_EQUAL(0,o31->edGetNumberOfOutLinks());
1233   CPPUNIT_ASSERT_EQUAL(0,i41->edGetNumberOfLinks());// <-- important
1234   //Test on forward update for deletion
1235   graph->edAddLink(o21,i41);
1236   graph->edAddLink(o31,i41);
1237   CPPUNIT_ASSERT_EQUAL(1,o21->edGetNumberOfOutLinks());
1238   CPPUNIT_ASSERT_EQUAL(1,o31->edGetNumberOfOutLinks());
1239   CPPUNIT_ASSERT_EQUAL(1,i41->edGetNumberOfLinks());
1240   n2->edRemovePort(o21);
1241   CPPUNIT_ASSERT_EQUAL(1,o31->edGetNumberOfOutLinks());
1242   CPPUNIT_ASSERT_EQUAL(1,i41->edGetNumberOfLinks());
1243   n3->edRemovePort(o31);
1244   CPPUNIT_ASSERT_EQUAL(0,i41->edGetNumberOfLinks());// <-- important
1245   o21=n2->edAddOutputPort("o21",Runtime::_tc_double);
1246   o31=n3->edAddOutputPort("o31",Runtime::_tc_double);
1247   //
1248   graph->edAddLink(o21,i41);
1249   graph->edAddLink(o31,i41);
1250   mySwitch->checkConsistency();
1251   CPPUNIT_ASSERT_EQUAL(1,o21->edGetNumberOfOutLinks());
1252   CPPUNIT_ASSERT_EQUAL(1,o31->edGetNumberOfOutLinks());
1253   CPPUNIT_ASSERT_EQUAL(1,i41->edGetNumberOfLinks());
1254   ToyNode *n5=new ToyNode("T5");
1255   InputPort *i51=n5->edAddInputPort("i51",Runtime::_tc_double);
1256   InputPort *i52=n5->edAddInputPort("i52",Runtime::_tc_double);
1257   OutputPort *o51=n5->edAddOutputPort("o51",Runtime::_tc_double);
1258   OutputPort *o52=n5->edAddOutputPort("o52",Runtime::_tc_double);
1259   i52->edInit(7.);
1260   mySwitch->edSetNode(17,n5);
1261   graph->edAddLink(o1,i51);
1262   CPPUNIT_ASSERT_EQUAL(1,o21->edGetNumberOfOutLinks());
1263   CPPUNIT_ASSERT_EQUAL(1,o31->edGetNumberOfOutLinks());
1264   CPPUNIT_ASSERT_EQUAL(0,o51->edGetNumberOfOutLinks());
1265   CPPUNIT_ASSERT_EQUAL(1,i41->edGetNumberOfLinks());
1266   graph->edAddLink(o51,i41);
1267   mySwitch->checkConsistency();
1268   CPPUNIT_ASSERT_EQUAL(1,o21->edGetNumberOfOutLinks());
1269   CPPUNIT_ASSERT_EQUAL(1,o31->edGetNumberOfOutLinks());
1270   CPPUNIT_ASSERT_EQUAL(1,o51->edGetNumberOfOutLinks());
1271   CPPUNIT_ASSERT_EQUAL(1,i41->edGetNumberOfLinks());
1272   graph->edRemoveLink(o31,i41);
1273   CPPUNIT_ASSERT_EQUAL(1,o21->edGetNumberOfOutLinks());
1274   CPPUNIT_ASSERT_EQUAL(0,o31->edGetNumberOfOutLinks());
1275   CPPUNIT_ASSERT_EQUAL(1,o51->edGetNumberOfOutLinks());
1276   CPPUNIT_ASSERT_EQUAL(1,i41->edGetNumberOfLinks());
1277   graph->edAddLink(o31,i41);
1278   mySwitch->checkConsistency();
1279   graph->edAddLink(o22,i42);
1280   graph->edAddLink(o32,i42);
1281   graph->edAddLink(o52,i42);
1282   mySwitch->checkConsistency();
1283   CPPUNIT_ASSERT_EQUAL(1,o21->edGetNumberOfOutLinks());
1284   CPPUNIT_ASSERT_EQUAL(1,o31->edGetNumberOfOutLinks());
1285   CPPUNIT_ASSERT_EQUAL(1,o51->edGetNumberOfOutLinks());
1286   CPPUNIT_ASSERT_EQUAL(1,i41->edGetNumberOfLinks());
1287   CPPUNIT_ASSERT_EQUAL(1,o22->edGetNumberOfOutLinks());
1288   CPPUNIT_ASSERT_EQUAL(1,o32->edGetNumberOfOutLinks());
1289   CPPUNIT_ASSERT_EQUAL(1,o52->edGetNumberOfOutLinks());
1290   CPPUNIT_ASSERT_EQUAL(1,i42->edGetNumberOfLinks());
1291   ToyNode *n6=new ToyNode("T6");
1292   InputPort *i61=n6->edAddInputPort("i61",Runtime::_tc_double);
1293   InputPort *i62=n6->edAddInputPort("i62",Runtime::_tc_double);
1294   OutputPort *o61=n6->edAddOutputPort("o61",Runtime::_tc_double);
1295   graph->edAddChild(n6);
1296   graph->edAddCFLink(mySwitch,n6);
1297   CPPUNIT_ASSERT_EQUAL(1,n6->getInGate()->getNumberOfBackLinks());
1298   CPPUNIT_ASSERT_EQUAL(0,i62->edGetNumberOfLinks());
1299   graph->edAddLink(o22,i62);
1300   CPPUNIT_ASSERT_EQUAL(1,i62->edGetNumberOfLinks());
1301   graph->edAddLink(o32,i62);
1302   graph->edAddLink(o52,i62);
1303   CPPUNIT_ASSERT_EQUAL(2,o22->edGetNumberOfOutLinks());
1304   CPPUNIT_ASSERT_EQUAL(2,o32->edGetNumberOfOutLinks());
1305   CPPUNIT_ASSERT_EQUAL(2,o52->edGetNumberOfOutLinks());
1306   CPPUNIT_ASSERT_EQUAL(1,i42->edGetNumberOfLinks());
1307   CPPUNIT_ASSERT_EQUAL(1,i62->edGetNumberOfLinks());
1308   graph->edRemoveChild(n6);//normally implies collector inputport deletion
1309   mySwitch->checkConsistency();
1310   CPPUNIT_ASSERT_EQUAL(1,o22->edGetNumberOfOutLinks());
1311   CPPUNIT_ASSERT_EQUAL(1,o32->edGetNumberOfOutLinks());
1312   CPPUNIT_ASSERT_EQUAL(1,o52->edGetNumberOfOutLinks());
1313   CPPUNIT_ASSERT_EQUAL(1,i42->edGetNumberOfLinks());
1314   CPPUNIT_ASSERT_EQUAL(0,i62->edGetNumberOfLinks());
1315   CPPUNIT_ASSERT_EQUAL(0,n6->getInGate()->getNumberOfBackLinks());
1316   graph->edAddChild(n6);
1317   graph->edAddCFLink(mySwitch,n6);
1318   CPPUNIT_ASSERT_EQUAL(1,n6->getInGate()->getNumberOfBackLinks());
1319   graph->edAddLink(o22,i62);
1320   CPPUNIT_ASSERT_EQUAL(1,i62->edGetNumberOfLinks());
1321   graph->edAddLink(o32,i62);
1322   graph->edAddLink(o52,i62);
1323   CPPUNIT_ASSERT_EQUAL(2,o22->edGetNumberOfOutLinks());
1324   CPPUNIT_ASSERT_EQUAL(2,o32->edGetNumberOfOutLinks());
1325   CPPUNIT_ASSERT_EQUAL(2,o52->edGetNumberOfOutLinks());
1326   CPPUNIT_ASSERT_EQUAL(1,i42->edGetNumberOfLinks());
1327   CPPUNIT_ASSERT_EQUAL(1,i62->edGetNumberOfLinks());
1328   n6->edRemovePort(i61);
1329   CPPUNIT_ASSERT_EQUAL(1,n6->getInGate()->getNumberOfBackLinks());
1330   CPPUNIT_ASSERT_EQUAL(2,o22->edGetNumberOfOutLinks());
1331   CPPUNIT_ASSERT_EQUAL(2,o32->edGetNumberOfOutLinks());
1332   CPPUNIT_ASSERT_EQUAL(2,o52->edGetNumberOfOutLinks());
1333   CPPUNIT_ASSERT_EQUAL(1,i42->edGetNumberOfLinks());
1334   CPPUNIT_ASSERT_EQUAL(1,i62->edGetNumberOfLinks());
1335   n6->edRemovePort(i62);//normally implies collector inputport deletion
1336   CPPUNIT_ASSERT_EQUAL(1,n6->getInGate()->getNumberOfBackLinks());
1337   CPPUNIT_ASSERT_EQUAL(1,o22->edGetNumberOfOutLinks());
1338   CPPUNIT_ASSERT_EQUAL(1,o32->edGetNumberOfOutLinks());
1339   CPPUNIT_ASSERT_EQUAL(1,o52->edGetNumberOfOutLinks());
1340   CPPUNIT_ASSERT_EQUAL(1,i42->edGetNumberOfLinks());
1341   graph->edRemoveLink(o32,i42);
1342   CPPUNIT_ASSERT_EQUAL(1,n6->getInGate()->getNumberOfBackLinks());
1343   CPPUNIT_ASSERT_EQUAL(1,o22->edGetNumberOfOutLinks());
1344   CPPUNIT_ASSERT_EQUAL(0,o32->edGetNumberOfOutLinks());
1345   CPPUNIT_ASSERT_EQUAL(1,o52->edGetNumberOfOutLinks());
1346   CPPUNIT_ASSERT_EQUAL(1,i42->edGetNumberOfLinks());
1347   n4->edRemovePort(i42);//normally implies collector inputport deletion
1348   CPPUNIT_ASSERT_EQUAL(0,o22->edGetNumberOfOutLinks());
1349   CPPUNIT_ASSERT_EQUAL(0,o32->edGetNumberOfOutLinks());
1350   //few forward link updates
1351   CPPUNIT_ASSERT_EQUAL(1,i21->edGetNumberOfLinks());
1352   CPPUNIT_ASSERT_EQUAL(1,i31->edGetNumberOfLinks());
1353   CPPUNIT_ASSERT_EQUAL(1,i51->edGetNumberOfLinks());
1354   CPPUNIT_ASSERT_EQUAL(3,o1->edGetNumberOfOutLinks());
1355   n1->edRemovePort(o1);
1356   CPPUNIT_ASSERT_EQUAL(0,i21->edGetNumberOfLinks());
1357   CPPUNIT_ASSERT_EQUAL(0,i31->edGetNumberOfLinks());
1358   CPPUNIT_ASSERT_EQUAL(0,i51->edGetNumberOfLinks());
1359   delete graph;
1360 }
1361
1362 /**
1363  * Idem testLinkUpdate1 but for DS.
1364  */
1365 void EngineIntegrationTest::testLinkUpdate1DS()
1366 {
1367   Bloc *graph=new Bloc("Graph");
1368
1369   ToyNode *n1=new ToyNode("T1");
1370   InputDataStreamPort *i11=n1->edAddInputDataStreamPort("i11",Runtime::_tc_double);
1371   OutputDataStreamPort *o1=n1->edAddOutputDataStreamPort("o1",Runtime::_tc_double);
1372   graph->edAddChild(n1);
1373   
1374   Switch *mySwitch=new Switch("mySwitch");
1375   graph->edAddChild(mySwitch);
1376   graph->edAddCFLink(n1,mySwitch);
1377
1378   ToyNode *n2=new ToyNode("T2");
1379   InputDataStreamPort *i21=n2->edAddInputDataStreamPort("i21",Runtime::_tc_double);
1380   InputDataStreamPort *i22=n2->edAddInputDataStreamPort("i22",Runtime::_tc_double);
1381   OutputDataStreamPort *o21=n2->edAddOutputDataStreamPort("o21",Runtime::_tc_double);
1382   OutputDataStreamPort *o22=n2->edAddOutputDataStreamPort("o22",Runtime::_tc_double);
1383   mySwitch->edSetNode(0,n2);
1384   graph->edAddLink(o1,i21);
1385   graph->edAddLink(n1->edGetNbOfInputsOutputPort(),mySwitch->edGetConditionPort());
1386   ToyNode *n3=new ToyNode("T3");
1387   Bloc *Bn3=new Bloc("Bn3");
1388   Bn3->edAddChild(n3);
1389   InputDataStreamPort *i31=n3->edAddInputDataStreamPort("i31",Runtime::_tc_double);
1390   InputDataStreamPort *i32=n3->edAddInputDataStreamPort("i32",Runtime::_tc_double);
1391   OutputDataStreamPort *o31=n3->edAddOutputDataStreamPort("o31",Runtime::_tc_double);
1392   OutputDataStreamPort *o32=n3->edAddOutputDataStreamPort("o32",Runtime::_tc_double);
1393   mySwitch->edSetNode(1,Bn3);
1394   graph->edAddLink(o1,i31);
1395   //
1396   ToyNode *n4=new ToyNode("T4");
1397   InputDataStreamPort *i41=n4->edAddInputDataStreamPort("i41",Runtime::_tc_double);
1398   InputDataStreamPort *i42=n4->edAddInputDataStreamPort("i42",Runtime::_tc_double);
1399   OutputDataStreamPort *o41=n4->edAddOutputDataStreamPort("o41",Runtime::_tc_double);
1400   graph->edAddChild(n4);
1401   graph->edAddCFLink(mySwitch,n4);
1402   graph->edAddLink(o21,i41);
1403   graph->edAddLink(o31,i41);
1404   mySwitch->checkConsistency();
1405   CPPUNIT_ASSERT_EQUAL(1,o21->edGetNumberOfOutLinks());
1406   CPPUNIT_ASSERT_EQUAL(1,o31->edGetNumberOfOutLinks());
1407   CPPUNIT_ASSERT_EQUAL(1,i41->edGetNumberOfLinks());// <-- important
1408   graph->edRemoveLink(o21,i41);
1409   CPPUNIT_ASSERT_EQUAL(0,o21->edGetNumberOfOutLinks());
1410   CPPUNIT_ASSERT_EQUAL(1,o31->edGetNumberOfOutLinks());
1411   CPPUNIT_ASSERT_EQUAL(1,i41->edGetNumberOfLinks());// <-- important
1412   graph->edRemoveLink(o31,i41);//normally implies collector inputport deletion
1413   CPPUNIT_ASSERT_EQUAL(0,o21->edGetNumberOfOutLinks());
1414   CPPUNIT_ASSERT_EQUAL(0,o31->edGetNumberOfOutLinks());
1415   CPPUNIT_ASSERT_EQUAL(0,i41->edGetNumberOfLinks());// <-- important
1416   //Test on forward update for deletion
1417   graph->edAddLink(o21,i41);
1418   graph->edAddLink(o31,i41);
1419   CPPUNIT_ASSERT_EQUAL(1,o21->edGetNumberOfOutLinks());
1420   CPPUNIT_ASSERT_EQUAL(1,o31->edGetNumberOfOutLinks());
1421   CPPUNIT_ASSERT_EQUAL(1,i41->edGetNumberOfLinks());
1422   n2->edRemovePort(o21);
1423   CPPUNIT_ASSERT_EQUAL(1,o31->edGetNumberOfOutLinks());
1424   CPPUNIT_ASSERT_EQUAL(1,i41->edGetNumberOfLinks());
1425   n3->edRemovePort(o31);
1426   CPPUNIT_ASSERT_EQUAL(0,i41->edGetNumberOfLinks());// <-- important
1427   o21=n2->edAddOutputDataStreamPort("o21",Runtime::_tc_double);
1428   o31=n3->edAddOutputDataStreamPort("o31",Runtime::_tc_double);
1429   //
1430   graph->edAddLink(o21,i41);
1431   graph->edAddLink(o31,i41);
1432   mySwitch->checkConsistency();
1433   CPPUNIT_ASSERT_EQUAL(1,o21->edGetNumberOfOutLinks());
1434   CPPUNIT_ASSERT_EQUAL(1,o31->edGetNumberOfOutLinks());
1435   CPPUNIT_ASSERT_EQUAL(1,i41->edGetNumberOfLinks());
1436   ToyNode *n5=new ToyNode("T5");
1437   InputDataStreamPort *i51=n5->edAddInputDataStreamPort("i51",Runtime::_tc_double);
1438   InputDataStreamPort *i52=n5->edAddInputDataStreamPort("i52",Runtime::_tc_double);
1439   OutputDataStreamPort *o51=n5->edAddOutputDataStreamPort("o51",Runtime::_tc_double);
1440   OutputDataStreamPort *o52=n5->edAddOutputDataStreamPort("o52",Runtime::_tc_double);
1441   mySwitch->edSetNode(17,n5);
1442   graph->edAddLink(o1,i51);
1443   CPPUNIT_ASSERT_EQUAL(1,o21->edGetNumberOfOutLinks());
1444   CPPUNIT_ASSERT_EQUAL(1,o31->edGetNumberOfOutLinks());
1445   CPPUNIT_ASSERT_EQUAL(0,o51->edGetNumberOfOutLinks());
1446   CPPUNIT_ASSERT_EQUAL(1,i41->edGetNumberOfLinks());
1447   graph->edAddLink(o51,i41);
1448   mySwitch->checkConsistency();
1449   CPPUNIT_ASSERT_EQUAL(1,o21->edGetNumberOfOutLinks());
1450   CPPUNIT_ASSERT_EQUAL(1,o31->edGetNumberOfOutLinks());
1451   CPPUNIT_ASSERT_EQUAL(1,o51->edGetNumberOfOutLinks());
1452   CPPUNIT_ASSERT_EQUAL(1,i41->edGetNumberOfLinks());
1453   graph->edRemoveLink(o31,i41);
1454   CPPUNIT_ASSERT_EQUAL(1,o21->edGetNumberOfOutLinks());
1455   CPPUNIT_ASSERT_EQUAL(0,o31->edGetNumberOfOutLinks());
1456   CPPUNIT_ASSERT_EQUAL(1,o51->edGetNumberOfOutLinks());
1457   CPPUNIT_ASSERT_EQUAL(1,i41->edGetNumberOfLinks());
1458   graph->edAddLink(o31,i41);
1459   mySwitch->checkConsistency();
1460   graph->edAddLink(o22,i42);
1461   graph->edAddLink(o32,i42);
1462   graph->edAddLink(o52,i42);
1463   mySwitch->checkConsistency();
1464   CPPUNIT_ASSERT_EQUAL(1,o21->edGetNumberOfOutLinks());
1465   CPPUNIT_ASSERT_EQUAL(1,o31->edGetNumberOfOutLinks());
1466   CPPUNIT_ASSERT_EQUAL(1,o51->edGetNumberOfOutLinks());
1467   CPPUNIT_ASSERT_EQUAL(1,i41->edGetNumberOfLinks());
1468   CPPUNIT_ASSERT_EQUAL(1,o22->edGetNumberOfOutLinks());
1469   CPPUNIT_ASSERT_EQUAL(1,o32->edGetNumberOfOutLinks());
1470   CPPUNIT_ASSERT_EQUAL(1,o52->edGetNumberOfOutLinks());
1471   CPPUNIT_ASSERT_EQUAL(1,i42->edGetNumberOfLinks());
1472   ToyNode *n6=new ToyNode("T6");
1473   InputDataStreamPort *i61=n6->edAddInputDataStreamPort("i61",Runtime::_tc_double);
1474   InputDataStreamPort *i62=n6->edAddInputDataStreamPort("i62",Runtime::_tc_double);
1475   OutputDataStreamPort *o61=n6->edAddOutputDataStreamPort("o61",Runtime::_tc_double);
1476   graph->edAddChild(n6);
1477   graph->edAddCFLink(mySwitch,n6);
1478   CPPUNIT_ASSERT_EQUAL(1,n6->getInGate()->getNumberOfBackLinks());
1479   CPPUNIT_ASSERT_EQUAL(0,i62->edGetNumberOfLinks());
1480   graph->edAddLink(o22,i62);
1481   CPPUNIT_ASSERT_EQUAL(1,i62->edGetNumberOfLinks());
1482   graph->edAddLink(o32,i62);
1483   graph->edAddLink(o52,i62);
1484   CPPUNIT_ASSERT_EQUAL(2,o22->edGetNumberOfOutLinks());
1485   CPPUNIT_ASSERT_EQUAL(2,o32->edGetNumberOfOutLinks());
1486   CPPUNIT_ASSERT_EQUAL(2,o52->edGetNumberOfOutLinks());
1487   CPPUNIT_ASSERT_EQUAL(1,i42->edGetNumberOfLinks());
1488   CPPUNIT_ASSERT_EQUAL(1,i62->edGetNumberOfLinks());
1489   graph->edRemoveChild(n6);//normally implies collector inputport deletion
1490   mySwitch->checkConsistency();
1491   CPPUNIT_ASSERT_EQUAL(1,o22->edGetNumberOfOutLinks());
1492   CPPUNIT_ASSERT_EQUAL(1,o32->edGetNumberOfOutLinks());
1493   CPPUNIT_ASSERT_EQUAL(1,o52->edGetNumberOfOutLinks());
1494   CPPUNIT_ASSERT_EQUAL(1,i42->edGetNumberOfLinks());
1495   CPPUNIT_ASSERT_EQUAL(0,i62->edGetNumberOfLinks());
1496   CPPUNIT_ASSERT_EQUAL(0,n6->getInGate()->getNumberOfBackLinks());
1497   graph->edAddChild(n6);
1498   graph->edAddCFLink(mySwitch,n6);
1499   CPPUNIT_ASSERT_EQUAL(1,n6->getInGate()->getNumberOfBackLinks());
1500   graph->edAddLink(o22,i62);
1501   CPPUNIT_ASSERT_EQUAL(1,i62->edGetNumberOfLinks());
1502   graph->edAddLink(o32,i62);
1503   graph->edAddLink(o52,i62);
1504   CPPUNIT_ASSERT_EQUAL(2,o22->edGetNumberOfOutLinks());
1505   CPPUNIT_ASSERT_EQUAL(2,o32->edGetNumberOfOutLinks());
1506   CPPUNIT_ASSERT_EQUAL(2,o52->edGetNumberOfOutLinks());
1507   CPPUNIT_ASSERT_EQUAL(1,i42->edGetNumberOfLinks());
1508   CPPUNIT_ASSERT_EQUAL(1,i62->edGetNumberOfLinks());
1509   n6->edRemovePort(i61);
1510   CPPUNIT_ASSERT_EQUAL(1,n6->getInGate()->getNumberOfBackLinks());
1511   CPPUNIT_ASSERT_EQUAL(2,o22->edGetNumberOfOutLinks());
1512   CPPUNIT_ASSERT_EQUAL(2,o32->edGetNumberOfOutLinks());
1513   CPPUNIT_ASSERT_EQUAL(2,o52->edGetNumberOfOutLinks());
1514   CPPUNIT_ASSERT_EQUAL(1,i42->edGetNumberOfLinks());
1515   CPPUNIT_ASSERT_EQUAL(1,i62->edGetNumberOfLinks());
1516   n6->edRemovePort(i62);//normally implies collector inputport deletion
1517   CPPUNIT_ASSERT_EQUAL(1,n6->getInGate()->getNumberOfBackLinks());
1518   CPPUNIT_ASSERT_EQUAL(1,o22->edGetNumberOfOutLinks());
1519   CPPUNIT_ASSERT_EQUAL(1,o32->edGetNumberOfOutLinks());
1520   CPPUNIT_ASSERT_EQUAL(1,o52->edGetNumberOfOutLinks());
1521   CPPUNIT_ASSERT_EQUAL(1,i42->edGetNumberOfLinks());
1522   graph->edRemoveLink(o32,i42);
1523   CPPUNIT_ASSERT_EQUAL(1,n6->getInGate()->getNumberOfBackLinks());
1524   CPPUNIT_ASSERT_EQUAL(1,o22->edGetNumberOfOutLinks());
1525   CPPUNIT_ASSERT_EQUAL(0,o32->edGetNumberOfOutLinks());
1526   CPPUNIT_ASSERT_EQUAL(1,o52->edGetNumberOfOutLinks());
1527   CPPUNIT_ASSERT_EQUAL(1,i42->edGetNumberOfLinks());
1528   n4->edRemovePort(i42);//normally implies collector inputport deletion
1529   CPPUNIT_ASSERT_EQUAL(0,o22->edGetNumberOfOutLinks());
1530   CPPUNIT_ASSERT_EQUAL(0,o32->edGetNumberOfOutLinks());
1531   //few forward link updates
1532   CPPUNIT_ASSERT_EQUAL(1,i21->edGetNumberOfLinks());
1533   CPPUNIT_ASSERT_EQUAL(1,i31->edGetNumberOfLinks());
1534   CPPUNIT_ASSERT_EQUAL(1,i51->edGetNumberOfLinks());
1535   CPPUNIT_ASSERT_EQUAL(3,o1->edGetNumberOfOutLinks());
1536   n1->edRemovePort(o1);
1537   CPPUNIT_ASSERT_EQUAL(0,i21->edGetNumberOfLinks());
1538   CPPUNIT_ASSERT_EQUAL(0,i31->edGetNumberOfLinks());
1539   CPPUNIT_ASSERT_EQUAL(0,i51->edGetNumberOfLinks());
1540   delete graph;
1541 }
1542
1543 // Less complex than testLinkUpdate1 only for Blocs update
1544 void EngineIntegrationTest::testLinkUpdate2()
1545 {
1546   Bloc *graph=new Bloc("Graph");
1547
1548   ToyNode *n1=new ToyNode("T1");
1549   InputPort *i11=n1->edAddInputPort("i11",Runtime::_tc_double);
1550   InputPort *i12=n1->edAddInputPort("i12",Runtime::_tc_double);
1551   InputPort *i13=n1->edAddInputPort("i13",Runtime::_tc_double);
1552   InputPort *i14=n1->edAddInputPort("i14",Runtime::_tc_double);
1553   OutputPort *o11=n1->edAddOutputPort("o11",Runtime::_tc_double);
1554   OutputPort *o12=n1->edAddOutputPort("o12",Runtime::_tc_double);
1555   OutputPort *o13=n1->edAddOutputPort("o13",Runtime::_tc_double);
1556   graph->edAddChild(n1);
1557   //
1558   Bloc *toto=new Bloc("toto");
1559   graph->edAddChild(toto);
1560   graph->edAddCFLink(n1,toto);
1561   ToyNode *n2=new ToyNode("T2");
1562   toto->edAddChild(n2);
1563   InputPort *i21=n2->edAddInputPort("i21",Runtime::_tc_double);
1564   InputPort *i22=n2->edAddInputPort("i22",Runtime::_tc_double);
1565   InputPort *i23=n2->edAddInputPort("i23",Runtime::_tc_double);
1566   OutputPort *o21=n2->edAddOutputPort("o21",Runtime::_tc_double);
1567   OutputPort *o22=n2->edAddOutputPort("o22",Runtime::_tc_double);
1568   OutputPort *o23=n2->edAddOutputPort("o23",Runtime::_tc_double);
1569   ToyNode *n3=new ToyNode("T3");
1570   toto->edAddChild(n3);
1571   InputPort *i31=n3->edAddInputPort("i31",Runtime::_tc_double);
1572   InputPort *i32=n3->edAddInputPort("i32",Runtime::_tc_double);
1573   InputPort *i33=n3->edAddInputPort("i33",Runtime::_tc_double);
1574   InputPort *i34=n3->edAddInputPort("i34",Runtime::_tc_double);
1575   OutputPort *o31=n3->edAddOutputPort("o31",Runtime::_tc_double);
1576   OutputPort *o32=n3->edAddOutputPort("o32",Runtime::_tc_double);
1577   OutputPort *o33=n3->edAddOutputPort("o33",Runtime::_tc_double);
1578   Bloc *totoSub=new Bloc("totoSub");
1579   toto->edAddChild(totoSub);
1580   toto->edAddCFLink(n2,totoSub);
1581   toto->edAddCFLink(totoSub,n3);
1582   ToyNode *n4=new ToyNode("T4");
1583   totoSub->edAddChild(n4);
1584   InputPort *i41=n4->edAddInputPort("i41",Runtime::_tc_double);
1585   InputPort *i42=n4->edAddInputPort("i42",Runtime::_tc_double);
1586   InputPort *i43=n4->edAddInputPort("i43",Runtime::_tc_double);
1587   OutputPort *o41=n4->edAddOutputPort("o41",Runtime::_tc_double);
1588   OutputPort *o44=n4->edAddOutputPort("o44",Runtime::_tc_double);
1589   OutputPort *o43=n4->edAddOutputPort("o43",Runtime::_tc_double);
1590   ToyNode *n5=new ToyNode("T5");
1591   totoSub->edAddChild(n5);
1592   totoSub->edAddCFLink(n4,n5);
1593   InputPort *i51=n5->edAddInputPort("i51",Runtime::_tc_double);
1594   InputPort *i52=n5->edAddInputPort("i52",Runtime::_tc_double);
1595   InputPort *i53=n5->edAddInputPort("i53",Runtime::_tc_double);
1596   InputPort *i54=n5->edAddInputPort("i54",Runtime::_tc_double);
1597   OutputPort *o51=n5->edAddOutputPort("o51",Runtime::_tc_double);
1598   OutputPort *o52=n5->edAddOutputPort("o52",Runtime::_tc_double);
1599   OutputPort *o53=n5->edAddOutputPort("o53",Runtime::_tc_double);
1600   ToyNode *n6=new ToyNode("T6");
1601   totoSub->edAddChild(n6);
1602   totoSub->edAddCFLink(n4,n6);
1603   InputPort *i61=n6->edAddInputPort("i61",Runtime::_tc_double);
1604   InputPort *i62=n6->edAddInputPort("i62",Runtime::_tc_double);
1605   InputPort *i63=n6->edAddInputPort("i63",Runtime::_tc_double);
1606   OutputPort *o61=n6->edAddOutputPort("o61",Runtime::_tc_double);
1607   OutputPort *o62=n6->edAddOutputPort("o62",Runtime::_tc_double);
1608   ToyNode *n7=new ToyNode("T7");
1609   totoSub->edAddChild(n7);
1610   totoSub->edAddCFLink(n6,n7);
1611   totoSub->edAddCFLink(n5,n7);
1612   InputPort *i71=n7->edAddInputPort("i71",Runtime::_tc_double);
1613   InputPort *i72=n7->edAddInputPort("i72",Runtime::_tc_double);
1614   InputPort *i73=n7->edAddInputPort("i73",Runtime::_tc_double);
1615   OutputPort *o71=n7->edAddOutputPort("o71",Runtime::_tc_double);
1616   OutputPort *o72=n7->edAddOutputPort("o72",Runtime::_tc_double);
1617   //
1618   Bloc *titi=new Bloc("titi");
1619   ToyNode *n8=new ToyNode("T8");
1620   graph->edAddChild(titi);
1621   titi->edAddChild(n8);
1622   InputPort *i81=n8->edAddInputPort("i81",Runtime::_tc_double);
1623   InputPort *i82=n8->edAddInputPort("i82",Runtime::_tc_double);
1624   InputPort *i83=n8->edAddInputPort("i83",Runtime::_tc_double);
1625   OutputPort *o81=n8->edAddOutputPort("o81",Runtime::_tc_double);
1626   OutputPort *o82=n8->edAddOutputPort("o82",Runtime::_tc_double);
1627   OutputDataStreamPort *o83=n8->edAddOutputDataStreamPort("o83",Runtime::_tc_double);
1628   graph->edAddCFLink(toto,titi);
1629   ToyNode *n9=new ToyNode("T9");
1630   graph->edAddChild(n9);
1631   graph->edAddCFLink(toto,n9);
1632   InputPort *i91=n9->edAddInputPort("i91",Runtime::_tc_double);
1633   InputPort *i92=n9->edAddInputPort("i92",Runtime::_tc_double);
1634   InputPort *i93=n9->edAddInputPort("i93",Runtime::_tc_double);
1635   OutputPort *o91=n9->edAddOutputPort("o91",Runtime::_tc_double);
1636   OutputPort *o92=n9->edAddOutputPort("o92",Runtime::_tc_double);
1637   // Let's test links updates ...
1638   graph->edAddLink(o61,i81);
1639   graph->edAddLink(o61,i72);
1640   graph->edAddLink(o61,i92);
1641   graph->edAddLink(o61,i33);
1642   graph->edAddLink(o12,i21); graph->edAddLink(o12,i31); graph->edAddLink(o12,i71); graph->edAddLink(o12,i82); graph->edAddLink(o12,i91);
1643   CPPUNIT_ASSERT_EQUAL(5,o12->edGetNumberOfOutLinks());
1644   CPPUNIT_ASSERT_EQUAL(1,i21->edGetNumberOfLinks());
1645   CPPUNIT_ASSERT_EQUAL(1,i31->edGetNumberOfLinks());
1646   CPPUNIT_ASSERT_EQUAL(1,i71->edGetNumberOfLinks());
1647   CPPUNIT_ASSERT_EQUAL(1,i82->edGetNumberOfLinks());
1648   CPPUNIT_ASSERT_EQUAL(1,i91->edGetNumberOfLinks());
1649   CPPUNIT_ASSERT_EQUAL(0,i32->edGetNumberOfLinks());
1650   //Test on link throw
1651   try
1652     {
1653       graph->edAddLink(o83,i51);
1654       CPPUNIT_ASSERT(0);
1655     }
1656   catch(Exception& e)
1657     {
1658       CPPUNIT_ASSERT(string(e.what())=="ComposedNode::checkLinkPossibility : Request for cross protocol link impossible.");
1659     }
1660   //
1661   CPPUNIT_ASSERT_EQUAL(4,o61->edGetNumberOfOutLinks());
1662   CPPUNIT_ASSERT_EQUAL(1,i81->edGetNumberOfLinks());
1663   CPPUNIT_ASSERT_EQUAL(1,i72->edGetNumberOfLinks());
1664   CPPUNIT_ASSERT_EQUAL(1,i92->edGetNumberOfLinks());
1665   CPPUNIT_ASSERT_EQUAL(1,i33->edGetNumberOfLinks());
1666   CPPUNIT_ASSERT_EQUAL(0,i32->edGetNumberOfLinks());
1667   CPPUNIT_ASSERT_EQUAL(2,(int)toto->getSetOfLinksLeavingCurrentScope().size());
1668   CPPUNIT_ASSERT_EQUAL(3,(int)totoSub->getSetOfLinksLeavingCurrentScope().size());
1669   CPPUNIT_ASSERT_EQUAL(1,n3->getInGate()->getNumberOfBackLinks());
1670   CPPUNIT_ASSERT_EQUAL(1,titi->getInGate()->getNumberOfBackLinks());
1671   CPPUNIT_ASSERT_EQUAL(0,n8->getInGate()->getNumberOfBackLinks());
1672   graph->edRemoveChild(toto);
1673   CPPUNIT_ASSERT_EQUAL(2,o12->edGetNumberOfOutLinks());
1674   CPPUNIT_ASSERT_EQUAL(0,i21->edGetNumberOfLinks());
1675   CPPUNIT_ASSERT_EQUAL(0,i31->edGetNumberOfLinks());
1676   CPPUNIT_ASSERT_EQUAL(0,i71->edGetNumberOfLinks());
1677   CPPUNIT_ASSERT_EQUAL(1,i82->edGetNumberOfLinks());
1678   CPPUNIT_ASSERT_EQUAL(1,i91->edGetNumberOfLinks());
1679   CPPUNIT_ASSERT_EQUAL(0,i32->edGetNumberOfLinks());
1680   CPPUNIT_ASSERT_EQUAL(1,n3->getInGate()->getNumberOfBackLinks());
1681   CPPUNIT_ASSERT_EQUAL(0,titi->getInGate()->getNumberOfBackLinks());
1682   CPPUNIT_ASSERT_EQUAL(0,n8->getInGate()->getNumberOfBackLinks());
1683   CPPUNIT_ASSERT_EQUAL(2,o61->edGetNumberOfOutLinks());
1684   CPPUNIT_ASSERT_EQUAL(0,i81->edGetNumberOfLinks());
1685   CPPUNIT_ASSERT_EQUAL(1,i72->edGetNumberOfLinks());
1686   CPPUNIT_ASSERT_EQUAL(0,i92->edGetNumberOfLinks());
1687   CPPUNIT_ASSERT_EQUAL(1,i33->edGetNumberOfLinks());
1688   CPPUNIT_ASSERT_EQUAL(0,i32->edGetNumberOfLinks());
1689   toto->edRemoveChild(totoSub);
1690   CPPUNIT_ASSERT_EQUAL(0,n3->getInGate()->getNumberOfBackLinks());
1691   CPPUNIT_ASSERT_EQUAL(0,titi->getInGate()->getNumberOfBackLinks());
1692   CPPUNIT_ASSERT_EQUAL(0,n8->getInGate()->getNumberOfBackLinks());
1693   CPPUNIT_ASSERT_EQUAL(1,o61->edGetNumberOfOutLinks());
1694   CPPUNIT_ASSERT_EQUAL(0,i81->edGetNumberOfLinks());
1695   CPPUNIT_ASSERT_EQUAL(1,i72->edGetNumberOfLinks());
1696   CPPUNIT_ASSERT_EQUAL(0,i92->edGetNumberOfLinks());
1697   CPPUNIT_ASSERT_EQUAL(0,i33->edGetNumberOfLinks());
1698   CPPUNIT_ASSERT_EQUAL(0,i32->edGetNumberOfLinks());
1699   delete toto;
1700   delete totoSub;
1701   //
1702   delete graph;
1703 }
1704
1705 /** 
1706  *idem testLinkUpdate2 but with DS
1707  */
1708 void EngineIntegrationTest::testLinkUpdate2DS()
1709 {
1710   Bloc *graph=new Bloc("Graph");
1711
1712   ToyNode *n1=new ToyNode("T1");
1713   InputDataStreamPort *i11=n1->edAddInputDataStreamPort("i11",Runtime::_tc_double);
1714   InputDataStreamPort *i12=n1->edAddInputDataStreamPort("i12",Runtime::_tc_double);
1715   InputDataStreamPort *i13=n1->edAddInputDataStreamPort("i13",Runtime::_tc_double);
1716   InputDataStreamPort *i14=n1->edAddInputDataStreamPort("i14",Runtime::_tc_double);
1717   OutputDataStreamPort *o11=n1->edAddOutputDataStreamPort("o11",Runtime::_tc_double);
1718   OutputDataStreamPort *o12=n1->edAddOutputDataStreamPort("o12",Runtime::_tc_double);
1719   OutputDataStreamPort *o13=n1->edAddOutputDataStreamPort("o13",Runtime::_tc_double);
1720   graph->edAddChild(n1);
1721   //
1722   Bloc *toto=new Bloc("toto");
1723   graph->edAddChild(toto);
1724   graph->edAddCFLink(n1,toto);
1725   ToyNode *n2=new ToyNode("T2");
1726   toto->edAddChild(n2);
1727   InputDataStreamPort *i21=n2->edAddInputDataStreamPort("i21",Runtime::_tc_double);
1728   InputDataStreamPort *i22=n2->edAddInputDataStreamPort("i22",Runtime::_tc_double);
1729   InputDataStreamPort *i23=n2->edAddInputDataStreamPort("i23",Runtime::_tc_double);
1730   OutputDataStreamPort *o21=n2->edAddOutputDataStreamPort("o21",Runtime::_tc_double);
1731   OutputDataStreamPort *o22=n2->edAddOutputDataStreamPort("o22",Runtime::_tc_double);
1732   OutputDataStreamPort *o23=n2->edAddOutputDataStreamPort("o23",Runtime::_tc_double);
1733   ToyNode *n3=new ToyNode("T3");
1734   toto->edAddChild(n3);
1735   InputDataStreamPort *i31=n3->edAddInputDataStreamPort("i31",Runtime::_tc_double);
1736   InputDataStreamPort *i32=n3->edAddInputDataStreamPort("i32",Runtime::_tc_double);
1737   InputDataStreamPort *i33=n3->edAddInputDataStreamPort("i33",Runtime::_tc_double);
1738   InputDataStreamPort *i34=n3->edAddInputDataStreamPort("i34",Runtime::_tc_double);
1739   OutputDataStreamPort *o31=n3->edAddOutputDataStreamPort("o31",Runtime::_tc_double);
1740   OutputDataStreamPort *o32=n3->edAddOutputDataStreamPort("o32",Runtime::_tc_double);
1741   OutputDataStreamPort *o33=n3->edAddOutputDataStreamPort("o33",Runtime::_tc_double);
1742   Bloc *totoSub=new Bloc("totoSub");
1743   toto->edAddChild(totoSub);
1744   toto->edAddCFLink(n2,totoSub);
1745   toto->edAddCFLink(totoSub,n3);
1746   ToyNode *n4=new ToyNode("T4");
1747   totoSub->edAddChild(n4);
1748   InputDataStreamPort *i41=n4->edAddInputDataStreamPort("i41",Runtime::_tc_double);
1749   InputDataStreamPort *i42=n4->edAddInputDataStreamPort("i42",Runtime::_tc_double);
1750   InputDataStreamPort *i43=n4->edAddInputDataStreamPort("i43",Runtime::_tc_double);
1751   OutputDataStreamPort *o41=n4->edAddOutputDataStreamPort("o41",Runtime::_tc_double);
1752   OutputDataStreamPort *o44=n4->edAddOutputDataStreamPort("o44",Runtime::_tc_double);
1753   OutputDataStreamPort *o43=n4->edAddOutputDataStreamPort("o43",Runtime::_tc_double);
1754   ToyNode *n5=new ToyNode("T5");
1755   totoSub->edAddChild(n5);
1756   totoSub->edAddCFLink(n4,n5);
1757   InputDataStreamPort *i51=n5->edAddInputDataStreamPort("i51",Runtime::_tc_double);
1758   InputDataStreamPort *i52=n5->edAddInputDataStreamPort("i52",Runtime::_tc_double);
1759   InputDataStreamPort *i53=n5->edAddInputDataStreamPort("i53",Runtime::_tc_double);
1760   InputDataStreamPort *i54=n5->edAddInputDataStreamPort("i54",Runtime::_tc_double);
1761   OutputDataStreamPort *o51=n5->edAddOutputDataStreamPort("o51",Runtime::_tc_double);
1762   OutputDataStreamPort *o52=n5->edAddOutputDataStreamPort("o52",Runtime::_tc_double);
1763   OutputDataStreamPort *o53=n5->edAddOutputDataStreamPort("o53",Runtime::_tc_double);
1764   ToyNode *n6=new ToyNode("T6");
1765   totoSub->edAddChild(n6);
1766   totoSub->edAddCFLink(n4,n6);
1767   InputDataStreamPort *i61=n6->edAddInputDataStreamPort("i61",Runtime::_tc_double);
1768   InputDataStreamPort *i62=n6->edAddInputDataStreamPort("i62",Runtime::_tc_double);
1769   InputDataStreamPort *i63=n6->edAddInputDataStreamPort("i63",Runtime::_tc_double);
1770   OutputDataStreamPort *o61=n6->edAddOutputDataStreamPort("o61",Runtime::_tc_double);
1771   OutputDataStreamPort *o62=n6->edAddOutputDataStreamPort("o62",Runtime::_tc_double);
1772   ToyNode *n7=new ToyNode("T7");
1773   totoSub->edAddChild(n7);
1774   totoSub->edAddCFLink(n6,n7);
1775   totoSub->edAddCFLink(n5,n7);
1776   InputDataStreamPort *i71=n7->edAddInputDataStreamPort("i71",Runtime::_tc_double);
1777   InputDataStreamPort *i72=n7->edAddInputDataStreamPort("i72",Runtime::_tc_double);
1778   InputDataStreamPort *i73=n7->edAddInputDataStreamPort("i73",Runtime::_tc_double);
1779   OutputDataStreamPort *o71=n7->edAddOutputDataStreamPort("o71",Runtime::_tc_double);
1780   OutputDataStreamPort *o72=n7->edAddOutputDataStreamPort("o72",Runtime::_tc_double);
1781   //
1782   Bloc *titi=new Bloc("titi");
1783   ToyNode *n8=new ToyNode("T8");
1784   graph->edAddChild(titi);
1785   titi->edAddChild(n8);
1786   InputDataStreamPort *i81=n8->edAddInputDataStreamPort("i81",Runtime::_tc_double);
1787   InputDataStreamPort *i82=n8->edAddInputDataStreamPort("i82",Runtime::_tc_double);
1788   InputDataStreamPort *i83=n8->edAddInputDataStreamPort("i83",Runtime::_tc_double);
1789   OutputDataStreamPort *o81=n8->edAddOutputDataStreamPort("o81",Runtime::_tc_double);
1790   OutputDataStreamPort *o82=n8->edAddOutputDataStreamPort("o82",Runtime::_tc_double);
1791   graph->edAddCFLink(toto,titi);
1792   ToyNode *n9=new ToyNode("T9");
1793   graph->edAddChild(n9);
1794   graph->edAddCFLink(toto,n9);
1795   InputDataStreamPort *i91=n9->edAddInputDataStreamPort("i91",Runtime::_tc_double);
1796   InputDataStreamPort *i92=n9->edAddInputDataStreamPort("i92",Runtime::_tc_double);
1797   InputDataStreamPort *i93=n9->edAddInputDataStreamPort("i93",Runtime::_tc_double);
1798   OutputDataStreamPort *o91=n9->edAddOutputDataStreamPort("o91",Runtime::_tc_double);
1799   OutputDataStreamPort *o92=n9->edAddOutputDataStreamPort("o92",Runtime::_tc_double);
1800   // Let's test links updates ...
1801   graph->edAddLink(o61,i81);
1802   graph->edAddLink(o61,i72);
1803   graph->edAddLink(o61,i92);
1804   graph->edAddLink(o61,i33);
1805   graph->edAddLink(o12,i21); graph->edAddLink(o12,i31); graph->edAddLink(o12,i71); graph->edAddLink(o12,i82); graph->edAddLink(o12,i91);
1806   CPPUNIT_ASSERT_EQUAL(5,o12->edGetNumberOfOutLinks());
1807   CPPUNIT_ASSERT_EQUAL(1,i21->edGetNumberOfLinks());
1808   CPPUNIT_ASSERT_EQUAL(1,i31->edGetNumberOfLinks());
1809   CPPUNIT_ASSERT_EQUAL(1,i71->edGetNumberOfLinks());
1810   CPPUNIT_ASSERT_EQUAL(1,i82->edGetNumberOfLinks());
1811   CPPUNIT_ASSERT_EQUAL(1,i91->edGetNumberOfLinks());
1812   CPPUNIT_ASSERT_EQUAL(0,i32->edGetNumberOfLinks());
1813   //
1814   CPPUNIT_ASSERT_EQUAL(4,o61->edGetNumberOfOutLinks());
1815   CPPUNIT_ASSERT_EQUAL(1,i81->edGetNumberOfLinks());
1816   CPPUNIT_ASSERT_EQUAL(1,i72->edGetNumberOfLinks());
1817   CPPUNIT_ASSERT_EQUAL(1,i92->edGetNumberOfLinks());
1818   CPPUNIT_ASSERT_EQUAL(1,i33->edGetNumberOfLinks());
1819   CPPUNIT_ASSERT_EQUAL(0,i32->edGetNumberOfLinks());
1820   CPPUNIT_ASSERT_EQUAL(2,(int)toto->getSetOfLinksLeavingCurrentScope().size());
1821   CPPUNIT_ASSERT_EQUAL(3,(int)totoSub->getSetOfLinksLeavingCurrentScope().size());
1822   CPPUNIT_ASSERT_EQUAL(1,n3->getInGate()->getNumberOfBackLinks());
1823   CPPUNIT_ASSERT_EQUAL(1,titi->getInGate()->getNumberOfBackLinks());
1824   CPPUNIT_ASSERT_EQUAL(0,n8->getInGate()->getNumberOfBackLinks());
1825   graph->edRemoveChild(toto);
1826   CPPUNIT_ASSERT_EQUAL(2,o12->edGetNumberOfOutLinks());
1827   CPPUNIT_ASSERT_EQUAL(0,i21->edGetNumberOfLinks());
1828   CPPUNIT_ASSERT_EQUAL(0,i31->edGetNumberOfLinks());
1829   CPPUNIT_ASSERT_EQUAL(0,i71->edGetNumberOfLinks());
1830   CPPUNIT_ASSERT_EQUAL(1,i82->edGetNumberOfLinks());
1831   CPPUNIT_ASSERT_EQUAL(1,i91->edGetNumberOfLinks());
1832   CPPUNIT_ASSERT_EQUAL(0,i32->edGetNumberOfLinks());
1833   CPPUNIT_ASSERT_EQUAL(1,n3->getInGate()->getNumberOfBackLinks());
1834   CPPUNIT_ASSERT_EQUAL(0,titi->getInGate()->getNumberOfBackLinks());
1835   CPPUNIT_ASSERT_EQUAL(0,n8->getInGate()->getNumberOfBackLinks());
1836   CPPUNIT_ASSERT_EQUAL(2,o61->edGetNumberOfOutLinks());
1837   CPPUNIT_ASSERT_EQUAL(0,i81->edGetNumberOfLinks());
1838   CPPUNIT_ASSERT_EQUAL(1,i72->edGetNumberOfLinks());
1839   CPPUNIT_ASSERT_EQUAL(0,i92->edGetNumberOfLinks());
1840   CPPUNIT_ASSERT_EQUAL(1,i33->edGetNumberOfLinks());
1841   CPPUNIT_ASSERT_EQUAL(0,i32->edGetNumberOfLinks());
1842   toto->edRemoveChild(totoSub);
1843   CPPUNIT_ASSERT_EQUAL(0,n3->getInGate()->getNumberOfBackLinks());
1844   CPPUNIT_ASSERT_EQUAL(0,titi->getInGate()->getNumberOfBackLinks());
1845   CPPUNIT_ASSERT_EQUAL(0,n8->getInGate()->getNumberOfBackLinks());
1846   CPPUNIT_ASSERT_EQUAL(1,o61->edGetNumberOfOutLinks());
1847   CPPUNIT_ASSERT_EQUAL(0,i81->edGetNumberOfLinks());
1848   CPPUNIT_ASSERT_EQUAL(1,i72->edGetNumberOfLinks());
1849   CPPUNIT_ASSERT_EQUAL(0,i92->edGetNumberOfLinks());
1850   CPPUNIT_ASSERT_EQUAL(0,i33->edGetNumberOfLinks());
1851   CPPUNIT_ASSERT_EQUAL(0,i32->edGetNumberOfLinks());
1852   delete toto;
1853   delete totoSub;
1854   //
1855   delete graph;
1856 }
1857
1858 /*!
1859  * test of links between 2 loops to simulate coupling.
1860  */
1861 void EngineIntegrationTest::testInterLoopDFLink()
1862 {
1863   Bloc *graph=new Bloc("Graph");
1864   ForLoop *loop1=new ForLoop("loop1"); graph->edAddChild(loop1);
1865   ForLoop *loop2=new ForLoop("loop2"); graph->edAddChild(loop2);
1866   Bloc *b4N1=new Bloc("b4N1"); loop1->edSetNode(b4N1); ToyNode *n1=new ToyNode("T1"); b4N1->edAddChild(n1);
1867   ToyNode *n2=new ToyNode("T2"); loop2->edSetNode(n2);
1868   InputPort *i11=n1->edAddInputPort("i11",Runtime::_tc_double);
1869   InputPort *i21=n2->edAddInputPort("i21",Runtime::_tc_double);
1870   OutputPort *o11=n1->edAddOutputPort("o11",Runtime::_tc_double);
1871   OutputPort *o21=n2->edAddOutputPort("o21",Runtime::_tc_double);
1872   CPPUNIT_ASSERT( graph->edAddLink(o11,i21) );
1873   CPPUNIT_ASSERT_EQUAL(1,i21->edGetNumberOfLinks());
1874   CPPUNIT_ASSERT_EQUAL(1,o11->edGetNumberOfOutLinks());
1875   CPPUNIT_ASSERT( !graph->edAddLink(o11,i21) );
1876   CPPUNIT_ASSERT_EQUAL(1,i21->edGetNumberOfLinks());
1877   CPPUNIT_ASSERT_EQUAL(1,o11->edGetNumberOfOutLinks());
1878   set<InPort *> setI1=o11->edSetInPort();
1879   CPPUNIT_ASSERT(*(setI1.begin()) == i21);
1880   set<OutPort *> setO1=i21->edSetOutPort();
1881   CPPUNIT_ASSERT(*(setO1.begin()) == o11);
1882   graph->edRemoveLink(o11,i21);
1883   CPPUNIT_ASSERT_EQUAL(0,i21->edGetNumberOfLinks());
1884   CPPUNIT_ASSERT_EQUAL(0,o11->edGetNumberOfOutLinks());
1885   CPPUNIT_ASSERT( graph->edAddLink(o11,i21) );
1886   CPPUNIT_ASSERT( !graph->edAddLink(o11,i21) );
1887   CPPUNIT_ASSERT_EQUAL(1,i21->edGetNumberOfLinks());
1888   CPPUNIT_ASSERT_EQUAL(1,o11->edGetNumberOfOutLinks());
1889   InputDataStreamPort *i22=n2->edAddInputDataStreamPort("i22",Runtime::_tc_double);
1890   CPPUNIT_ASSERT( graph->edAddLink(o11,i22) );//DF-DS link
1891   CPPUNIT_ASSERT_EQUAL(1,i21->edGetNumberOfLinks());
1892   CPPUNIT_ASSERT_EQUAL(2,o11->edGetNumberOfOutLinks());
1893   CPPUNIT_ASSERT_EQUAL(1,i22->edGetNumberOfLinks());
1894   graph->edRemoveLink(o11,i21);
1895   CPPUNIT_ASSERT_EQUAL(0,i21->edGetNumberOfLinks());
1896   CPPUNIT_ASSERT_EQUAL(1,o11->edGetNumberOfOutLinks());
1897   CPPUNIT_ASSERT_EQUAL(1,i22->edGetNumberOfLinks());
1898   graph->edRemoveLink(o11,i22);
1899   CPPUNIT_ASSERT_EQUAL(0,i21->edGetNumberOfLinks());
1900   CPPUNIT_ASSERT_EQUAL(0,o11->edGetNumberOfOutLinks());
1901   CPPUNIT_ASSERT_EQUAL(0,i22->edGetNumberOfLinks());
1902   CPPUNIT_ASSERT( graph->edAddLink(o11,i21) );
1903   CPPUNIT_ASSERT_EQUAL(1,i21->edGetNumberOfLinks());
1904   CPPUNIT_ASSERT_EQUAL(1,o11->edGetNumberOfOutLinks());
1905   setI1=o11->edSetInPort();
1906   CPPUNIT_ASSERT(*(setI1.begin()) == i21);
1907   setO1=i21->edSetOutPort();
1908   CPPUNIT_ASSERT(*(setO1.begin()) == o11);
1909   CPPUNIT_ASSERT( graph->edAddLink(o11,i22) );
1910   CPPUNIT_ASSERT_EQUAL(1,i21->edGetNumberOfLinks());
1911   CPPUNIT_ASSERT_EQUAL(2,o11->edGetNumberOfOutLinks());
1912   CPPUNIT_ASSERT_EQUAL(1,i22->edGetNumberOfLinks());
1913   ElementaryNode *n=(ElementaryNode *)loop2->edRemoveNode();
1914   CPPUNIT_ASSERT_EQUAL(0,o11->edGetNumberOfOutLinks());
1915   //
1916   loop2->edSetNode(n);
1917   CPPUNIT_ASSERT(n==n2);
1918   OutputDataStreamPort *o22=n->edAddOutputDataStreamPort("o22",Runtime::_tc_double);
1919   CPPUNIT_ASSERT( graph->edAddLink(o22,i11) );//DS-DF Link
1920   CPPUNIT_ASSERT_EQUAL(0,o11->edGetNumberOfOutLinks());
1921   CPPUNIT_ASSERT_EQUAL(1,o22->edGetNumberOfOutLinks());
1922   CPPUNIT_ASSERT_EQUAL(1,i11->edGetNumberOfLinks());
1923   graph->edRemoveLink(o22,i11);
1924   CPPUNIT_ASSERT_EQUAL(0,o11->edGetNumberOfOutLinks());
1925   CPPUNIT_ASSERT_EQUAL(0,o22->edGetNumberOfOutLinks());
1926   CPPUNIT_ASSERT_EQUAL(0,i11->edGetNumberOfLinks());
1927   CPPUNIT_ASSERT( graph->edAddLink(o22,i11) );
1928   CPPUNIT_ASSERT_EQUAL(0,o11->edGetNumberOfOutLinks());
1929   CPPUNIT_ASSERT_EQUAL(1,o22->edGetNumberOfOutLinks());
1930   CPPUNIT_ASSERT_EQUAL(1,i11->edGetNumberOfLinks());
1931   InputDataStreamPort *i13=n1->edAddInputDataStreamPort("i13",Runtime::_tc_double);
1932   CPPUNIT_ASSERT( graph->edAddLink(o22,i13) );//interloop DS-DS Link
1933   CPPUNIT_ASSERT_EQUAL(0,o11->edGetNumberOfOutLinks());
1934   CPPUNIT_ASSERT_EQUAL(2,o22->edGetNumberOfOutLinks());
1935   CPPUNIT_ASSERT_EQUAL(1,i11->edGetNumberOfLinks());
1936   CPPUNIT_ASSERT_EQUAL(1,i13->edGetNumberOfLinks());
1937   graph->edRemoveLink(o22,i13);
1938   CPPUNIT_ASSERT_EQUAL(0,o11->edGetNumberOfOutLinks());
1939   CPPUNIT_ASSERT_EQUAL(1,o22->edGetNumberOfOutLinks());
1940   CPPUNIT_ASSERT_EQUAL(1,i11->edGetNumberOfLinks());
1941   CPPUNIT_ASSERT_EQUAL(0,i13->edGetNumberOfLinks());
1942   graph->edRemoveLink(o22,i11);
1943   CPPUNIT_ASSERT_EQUAL(0,o11->edGetNumberOfOutLinks());
1944   CPPUNIT_ASSERT_EQUAL(0,o22->edGetNumberOfOutLinks());
1945   CPPUNIT_ASSERT_EQUAL(0,i11->edGetNumberOfLinks());
1946   CPPUNIT_ASSERT_EQUAL(0,i13->edGetNumberOfLinks());
1947   delete graph;
1948 }
1949
1950 /*!
1951  * test of links between 2 loops to simulate coupling.
1952  */
1953 void EngineIntegrationTest::deathTestForLinks()
1954 {
1955   Bloc *graph=new Bloc("Graph");
1956   Bloc *b1=new Bloc("b1"); Bloc *b2=new Bloc("b2"); graph->edAddChild(b1); graph->edAddChild(b2);
1957   ForLoop *loop1=new ForLoop("loop1"); b1->edAddChild(loop1);
1958   ForLoop *loop2=new ForLoop("loop2"); b2->edAddChild(loop2);
1959   Bloc *b11=new Bloc("b11"); loop1->edSetNode(b11);
1960   Bloc *b21=new Bloc("b21"); loop2->edSetNode(b21);
1961   ToyNode *n22=new ToyNode("T22"); b21->edAddChild(n22);
1962   Switch *sw12=new Switch("sw12"); b11->edAddChild(sw12);
1963   Bloc *b13=new Bloc("b13"); sw12->edSetNode(7,b13);
1964   Switch *sw14=new Switch("sw14"); b13->edAddChild(sw14);
1965   Bloc *b15=new Bloc("b15"); sw14->edSetNode(9,b15);
1966   ToyNode *n16=new ToyNode("T16"); b15->edAddChild(n16);
1967   //Let's link
1968   OutputPort *o16_1=n16->edAddOutputPort("o16_1",Runtime::_tc_double);
1969   InputPort *i22_1=n22->edAddInputPort("i22_1",Runtime::_tc_double);
1970   CPPUNIT_ASSERT( graph->edAddLink(o16_1,i22_1) );
1971   CPPUNIT_ASSERT_EQUAL(1,o16_1->edGetNumberOfOutLinks());
1972   CPPUNIT_ASSERT_EQUAL(1,i22_1->edGetNumberOfLinks());
1973   graph->edRemoveLink(o16_1,i22_1);
1974   CPPUNIT_ASSERT_EQUAL(0,o16_1->edGetNumberOfOutLinks());
1975   CPPUNIT_ASSERT_EQUAL(0,i22_1->edGetNumberOfLinks());
1976   CPPUNIT_ASSERT( graph->edAddLink(o16_1,i22_1) );
1977   CPPUNIT_ASSERT( !graph->edAddLink(o16_1,i22_1) );
1978   CPPUNIT_ASSERT_EQUAL(1,o16_1->edGetNumberOfOutLinks());
1979   CPPUNIT_ASSERT_EQUAL(1,i22_1->edGetNumberOfLinks());
1980   set<InPort *> setI1=o16_1->edSetInPort();
1981   CPPUNIT_ASSERT(*(setI1.begin()) == i22_1);
1982   vector<DataPort *> vec=o16_1->calculateHistoryOfLinkWith(i22_1);
1983   string path;
1984   for(vector<DataPort *>::iterator iter=vec.begin();iter!=vec.end();iter++)
1985     { path+=(*iter)->getNameOfTypeOfCurrentInstance(); path+=" * "; }
1986   CPPUNIT_ASSERT ( path == "OutputPort * OutputPort * OutputPort * OutputDataStreamPort * InputDataStreamPort * InputPort * ");
1987   graph->edRemoveLink(o16_1,i22_1);
1988   CPPUNIT_ASSERT_EQUAL(0,o16_1->edGetNumberOfOutLinks());
1989   CPPUNIT_ASSERT_EQUAL(0,i22_1->edGetNumberOfLinks());
1990   CPPUNIT_ASSERT( graph->edAddLink(o16_1,i22_1) );
1991   CPPUNIT_ASSERT( !graph->edAddLink(o16_1,i22_1) );
1992   CPPUNIT_ASSERT_EQUAL(1,o16_1->edGetNumberOfOutLinks());
1993   CPPUNIT_ASSERT_EQUAL(1,i22_1->edGetNumberOfLinks());
1994   path="";
1995   vec=o16_1->calculateHistoryOfLinkWith(i22_1);
1996   for(vector<DataPort *>::iterator iter=vec.begin();iter!=vec.end();iter++)
1997     { path+=(*iter)->getNameOfTypeOfCurrentInstance(); path+=" * "; }
1998   CPPUNIT_ASSERT ( path == "OutputPort * OutputPort * OutputPort * OutputDataStreamPort * InputDataStreamPort * InputPort * ");
1999   graph->edRemoveLink(o16_1,i22_1);
2000   CPPUNIT_ASSERT_EQUAL(0,o16_1->edGetNumberOfOutLinks());
2001   CPPUNIT_ASSERT_EQUAL(0,i22_1->edGetNumberOfLinks());
2002   delete graph;
2003 }
2004
2005 void EngineIntegrationTest::testForEachLoop1()
2006 {
2007   Bloc *graph=new Bloc("graph");
2008   ForEachLoop *forEach=new ForEachLoop("myFE",Runtime::_tc_double);
2009   graph->edAddChild(forEach);
2010   ToyNode *n1=new ToyNode("T1");
2011   InputPort *i11=n1->edAddInputPort("i11",Runtime::_tc_double); i11->edInit(1.3);
2012   InputPort *i12=n1->edAddInputPort("i12",Runtime::_tc_double); i12->edInit(3.4);
2013   InputPort *i13=n1->edAddInputPort("i13",Runtime::_tc_double); i13->edInit(5.6);
2014   OutputPort *o11=n1->edAddOutputPort("o11",Runtime::_tc_double);
2015   graph->edAddChild(n1);
2016   graph->edAddCFLink(n1,forEach);
2017   SeqToyNode *n2=new SeqToyNode("T2");
2018   graph->edAddChild(n2);
2019   graph->edAddCFLink(n2,forEach);
2020   graph->edAddLink(n1->edGetNbOfInputsOutputPort(),forEach->edGetNbOfBranchesPort());
2021   graph->edAddLink(n2->edGetSeqOut(),forEach->edGetSeqOfSamplesPort());
2022   n2->edGetInIntValue()->edInit(5);
2023   ToyNode *n3=new ToyNode("T3");
2024   InputPort *i31=n3->edAddInputPort("i31",Runtime::_tc_double); i31->edInit(2.);
2025   InputPort *i32=n3->edAddInputPort("i32",Runtime::_tc_double);
2026   OutputPort *o31=n3->edAddOutputPort("o31",Runtime::_tc_double);
2027   forEach->edSetNode(n3);
2028   Seq2ToyNode *n4=new Seq2ToyNode("sequencer");
2029   graph->edAddChild(n4);
2030   graph->edAddCFLink(forEach,n4);
2031   graph->edAddLink(forEach->edGetSamplePort(),i32);
2032   graph->edAddLink(o31,n4->edGetInValue1());
2033   graph->edAddLink(n2->edGetSeqOut(),n4->edGetInValue2());
2034   int tab[]={12,14,16,18,20};
2035   vector<int> tabv(tab,tab+5);
2036   SequenceAnyPtr tmp=SequenceAny::New(tabv);//expected sequence
2037   Executor exe;
2038   exe.RunW(graph);
2039   CPPUNIT_ASSERT_EQUAL(3,(int)forEach->getNumberOfBranchesCreatedDyn());
2040   Any *val=n4->edGetSeqOut()->get();
2041   CPPUNIT_ASSERT( *val==*tmp );
2042   exe.RunW(graph);
2043   CPPUNIT_ASSERT_EQUAL(3,(int)forEach->getNumberOfBranchesCreatedDyn());
2044   n1->edRemovePort(i13);
2045   exe.RunW(graph);
2046   val=n4->edGetSeqOut()->get();
2047   CPPUNIT_ASSERT( *val==*tmp );
2048   CPPUNIT_ASSERT_EQUAL(2,(int)forEach->getNumberOfBranchesCreatedDyn());
2049   exe.RunW(graph);
2050   val=n4->edGetSeqOut()->get();
2051   CPPUNIT_ASSERT( *val==*tmp );
2052   CPPUNIT_ASSERT_EQUAL(2,(int)forEach->getNumberOfBranchesCreatedDyn());
2053   Bloc *graph2=(Bloc *)graph->clone(0);
2054   delete graph;
2055   exe.RunW(graph2);
2056   CPPUNIT_ASSERT_EQUAL(2,(int)((ForEachLoop *)graph2->getChildByName("myFE"))->getNumberOfBranchesCreatedDyn());
2057   exe.RunW(graph2);
2058   CPPUNIT_ASSERT_EQUAL(2,(int)((ForEachLoop *)graph2->getChildByName("myFE"))->getNumberOfBranchesCreatedDyn());
2059   n4=(Seq2ToyNode *)graph2->getChildByName("sequencer");
2060   val=n4->edGetSeqOut()->get();
2061   CPPUNIT_ASSERT( *val==*tmp );
2062   delete graph2;
2063 }
2064
2065 void EngineIntegrationTest::testForEachLoop2()
2066 {
2067   Bloc *graph=new Bloc("graph");
2068   ForEachLoop *forEach=new ForEachLoop("myFE",Runtime::_tc_double);
2069   graph->edAddChild(forEach);
2070   ToyNode *n1=new ToyNode("T1");
2071   InputPort *i11=n1->edAddInputPort("i11",Runtime::_tc_double); i11->edInit(1.3);
2072   InputPort *i12=n1->edAddInputPort("i12",Runtime::_tc_double); i12->edInit(3.4);
2073   InputPort *i13=n1->edAddInputPort("i13",Runtime::_tc_double); i13->edInit(5.6);
2074   OutputPort *o11=n1->edAddOutputPort("o11",Runtime::_tc_double);
2075   graph->edAddChild(n1);
2076   graph->edAddCFLink(n1,forEach);
2077   SeqToyNode *n2=new SeqToyNode("T2");
2078   graph->edAddChild(n2);
2079   graph->edAddCFLink(n2,forEach);
2080   graph->edAddLink(n1->edGetNbOfInputsOutputPort(),forEach->edGetNbOfBranchesPort());
2081   graph->edAddLink(n2->edGetSeqOut(),forEach->edGetSeqOfSamplesPort());
2082   n2->edGetInIntValue()->edInit(5);
2083   Bloc *blocToShakeBaby=new Bloc("blocToShakeBaby");
2084   ToyNode *n3=new ToyNode("T3");
2085   blocToShakeBaby->edAddChild(n3);
2086   InputPort *i31=n3->edAddInputPort("i31",Runtime::_tc_double); i31->edInit(2.);
2087   InputPort *i32=n3->edAddInputPort("i32",Runtime::_tc_double);
2088   OutputPort *o31=n3->edAddOutputPort("o31",Runtime::_tc_double);
2089   forEach->edSetNode(blocToShakeBaby);
2090   Seq2ToyNode *n4=new Seq2ToyNode("sequencer");
2091   graph->edAddChild(n4);
2092   graph->edAddCFLink(forEach,n4);
2093   graph->edAddLink(forEach->edGetSamplePort(),i32);
2094   graph->edAddLink(o31,n4->edGetInValue1());
2095   graph->edAddLink(n2->edGetSeqOut(),n4->edGetInValue2());
2096   CPPUNIT_ASSERT(dynamic_cast<AnySplitOutputPort *>(graph->getOutputPort("myFE.blocToShakeBaby.T3.o31")));
2097   int tab[]={12,14,16,18,20};
2098   vector<int> tabv(tab,tab+5);
2099   SequenceAnyPtr tmp=SequenceAny::New(tabv);//expected sequence
2100   Executor exe;
2101   exe.RunW(graph);
2102   CPPUNIT_ASSERT_EQUAL(3,(int)forEach->getNumberOfBranchesCreatedDyn());
2103   Any *val=n4->edGetSeqOut()->get();
2104   CPPUNIT_ASSERT( *val==*tmp );
2105   exe.RunW(graph);
2106   CPPUNIT_ASSERT_EQUAL(3,(int)forEach->getNumberOfBranchesCreatedDyn());
2107   n1->edRemovePort(i13);
2108   exe.RunW(graph);
2109   val=n4->edGetSeqOut()->get();
2110   CPPUNIT_ASSERT( *val==*tmp );
2111   CPPUNIT_ASSERT_EQUAL(2,(int)forEach->getNumberOfBranchesCreatedDyn());
2112   exe.RunW(graph);
2113   val=n4->edGetSeqOut()->get();
2114   CPPUNIT_ASSERT( *val==*tmp );
2115   CPPUNIT_ASSERT_EQUAL(2,(int)forEach->getNumberOfBranchesCreatedDyn());
2116   Bloc *graph2=(Bloc *)graph->clone(0);
2117   delete graph;
2118   exe.RunW(graph2);
2119   CPPUNIT_ASSERT_EQUAL(2,(int)((ForEachLoop *)graph2->getChildByName("myFE"))->getNumberOfBranchesCreatedDyn());
2120   exe.RunW(graph2);
2121   CPPUNIT_ASSERT_EQUAL(2,(int)((ForEachLoop *)graph2->getChildByName("myFE"))->getNumberOfBranchesCreatedDyn());
2122   n4=(Seq2ToyNode *)graph2->getChildByName("sequencer");
2123   val=n4->edGetSeqOut()->get();
2124   CPPUNIT_ASSERT( *val==*tmp );
2125   delete graph2;
2126 }
2127
2128 //Multi inclusion of ForEach
2129 void EngineIntegrationTest::testForEachLoop3()
2130 {
2131   Bloc *graph=new Bloc("graph");
2132   ForEachLoop *forEach1=new ForEachLoop("myFE1",Runtime::_tc_double);
2133   TypeCodeSeq *tc1=new TypeCodeSeq("","",Runtime::_tc_double);
2134   ForEachLoop *forEach2=new ForEachLoop("myFE2",tc1);
2135   SequenceAnyPtr tmpI=SequenceAny::New(tc1,3);//value as input
2136   tc1->decrRef();
2137   tc1=new TypeCodeSeq("","",Runtime::_tc_int);
2138   SequenceAnyPtr tmpO=SequenceAny::New(tc1,3);//value expected
2139   tc1->decrRef();
2140   graph->edAddChild(forEach2);
2141   forEach2->edSetNode(forEach1);
2142   ToyNode *n1=new ToyNode("T1");
2143   InputPort *i11=n1->edAddInputPort("i11",Runtime::_tc_double); i11->edInit(9.);
2144   InputPort *i12=n1->edAddInputPort("i12",Runtime::_tc_double);
2145   OutputPort *o11=n1->edAddOutputPort("o11",Runtime::_tc_double);
2146   OutputPort *o12=n1->edAddOutputPort("o12",Runtime::_tc_double);
2147   OutputPort *o13=n1->edAddOutputPort("o13",Runtime::_tc_double);
2148   forEach1->edSetNode(n1);
2149   graph->edAddLink(forEach2->edGetSamplePort(),forEach1->edGetSeqOfSamplesPort());
2150   graph->edAddLink(forEach1->edGetSamplePort(),i12);
2151   Seq3ToyNode *n2=new Seq3ToyNode("T2");
2152   graph->edAddChild(n2);
2153   graph->edAddLink(o11,n2->edGetInValue1());
2154   graph->edAddLink(o13,n2->edGetInValue2());
2155   graph->edAddCFLink(forEach2,n2);
2156   forEach1->edGetNbOfBranchesPort()->edInit(5);
2157   forEach2->edGetNbOfBranchesPort()->edInit(10);
2158   //Preparing input matrix
2159   double tab1[]={3.,6.,9.,12.,15.};
2160   double tab2[]={18.,21.,24.,27.,30.};
2161   double tab3[]={33.,36.,39.,42.,42.};
2162   vector<double> tabv1(tab1,tab1+5);
2163   vector<double> tabv2(tab2,tab2+5);
2164   vector<double> tabv3(tab3,tab3+5);
2165   SequenceAnyPtr tmp=SequenceAny::New(tabv1);
2166   tmpI->setEltAtRank(0,tmp);
2167   tmp=SequenceAny::New(tabv2);
2168   tmpI->setEltAtRank(1,tmp);
2169   tmp=SequenceAny::New(tabv3);
2170   tmpI->setEltAtRank(2,tmp);
2171   forEach2->edGetSeqOfSamplesPort()->edInit((Any *)tmpI);
2172   //preparing expected matrix
2173   int tab1I[]={8,10,12,14,16};
2174   int tab2I[]={18,20,22,24,26};
2175   int tab3I[]={28,30,32,34,34};
2176   vector<int> tabvI1(tab1I,tab1I+5);
2177   vector<int> tabvI2(tab2I,tab2I+5);
2178   vector<int> tabvI3(tab3I,tab3I+5);
2179   tmp=SequenceAny::New(tabvI1);
2180   tmpO->setEltAtRank(0,tmp);
2181   tmp=SequenceAny::New(tabvI2);
2182   tmpO->setEltAtRank(1,tmp);
2183   tmp=SequenceAny::New(tabvI3);
2184   tmpO->setEltAtRank(2,tmp);
2185   Executor exe;
2186   exe.RunW(graph);
2187   CPPUNIT_ASSERT_EQUAL(3,(int)forEach2->getNumberOfBranchesCreatedDyn());
2188   Any *val=n2->edGetSeqOut()->get();
2189   CPPUNIT_ASSERT( *val==*tmpO );
2190   exe.RunW(graph);
2191   CPPUNIT_ASSERT_EQUAL(3,(int)forEach2->getNumberOfBranchesCreatedDyn());
2192   val=n2->edGetSeqOut()->get();
2193   CPPUNIT_ASSERT( *val==*tmpO );
2194   ForEachLoop *clone=(ForEachLoop *)forEach2->clone(0);
2195   try
2196     {
2197       clone->getNumberOfBranchesCreatedDyn();
2198       CPPUNIT_ASSERT(false);
2199     }
2200   catch(Exception& e)
2201     {
2202       CPPUNIT_ASSERT( string(e.what())=="ForEachLoop::getNumberOfBranches : No branches created dynamically ! - ForEachLoop needs to run or to be runned to call getNumberOfBranches");
2203     }
2204   Bloc *graphCloned=(Bloc *)graph->clone(0);
2205   delete graph;
2206   exe.RunW(clone);
2207   CPPUNIT_ASSERT_EQUAL(3,(int)clone->getNumberOfBranchesCreatedDyn());
2208   exe.RunW(clone);
2209   CPPUNIT_ASSERT_EQUAL(3,(int)clone->getNumberOfBranchesCreatedDyn());
2210   exe.RunW(graphCloned);
2211   CPPUNIT_ASSERT_EQUAL(3,(int)((ForEachLoop *)graphCloned->getChildByName("myFE2"))->getNumberOfBranchesCreatedDyn());
2212   val=((Seq3ToyNode *) graphCloned->getChildByName("T2"))->edGetSeqOut()->get();
2213   CPPUNIT_ASSERT( *val==*tmpO );
2214   exe.RunW(graphCloned);
2215   CPPUNIT_ASSERT_EQUAL(3,(int)((ForEachLoop *)graphCloned->getChildByName("myFE2"))->getNumberOfBranchesCreatedDyn());
2216   val=((Seq3ToyNode *) graphCloned->getChildByName("T2"))->edGetSeqOut()->get();
2217   CPPUNIT_ASSERT( *val==*tmpO );
2218   delete graphCloned;
2219   delete clone;
2220 }
2221
2222 void EngineIntegrationTest::testForEachLoop4()
2223 {
2224   Bloc *graph=new Bloc("graph");
2225   ForEachLoop *forEach1=new ForEachLoop("myFE1",Runtime::_tc_int);
2226   Switch *sw=new Switch("Sw1");
2227   forEach1->edSetNode(sw);
2228   graph->edAddChild(forEach1);
2229   SeqToyNode *n0=new SeqToyNode("T0");
2230   graph->edAddChild(n0);
2231   n0->edGetInIntValue()->edInit(5);
2232   ToyNode *n1=new ToyNode("T1");
2233   InputPort *i11=n1->edAddInputPort("i11",Runtime::_tc_double); i11->edInit(9.);
2234   InputPort *i12=n1->edAddInputPort("i12",Runtime::_tc_double); i12->edInit(8.);
2235   OutputPort *o11=n1->edAddOutputPort("o11",Runtime::_tc_double);
2236   graph->edAddChild(n1);
2237   Seq2ToyNode *n2=new Seq2ToyNode("T2");
2238   graph->edAddChild(n2);
2239   graph->edAddCFLink(n0,forEach1);
2240   graph->edAddCFLink(n1,forEach1);
2241   graph->edAddCFLink(forEach1,n2);
2242   ToyNode *n3=new ToyNode("T3");
2243   InputPort *i31=n3->edAddInputPort("i31",Runtime::_tc_double);
2244   InputPort *i32=n3->edAddInputPort("i32",Runtime::_tc_double); i32->edInit(5.);
2245   OutputPort *o31=n3->edAddOutputPort("o31",Runtime::_tc_double);
2246   sw->edSetNode(2,n3);
2247   ToyNode *n4=new ToyNode("T4");
2248   InputPort *i41=n4->edAddInputPort("i41",Runtime::_tc_double); i41->edInit(5.);
2249   InputPort *i42=n4->edAddInputPort("i42",Runtime::_tc_double); 
2250   InputPort *i43=n4->edAddInputPort("i43",Runtime::_tc_double); i43->edInit(7.);
2251   OutputPort *o41=n4->edAddOutputPort("o41",Runtime::_tc_double);
2252   OutputPort *o42=n4->edAddOutputPort("o42",Runtime::_tc_double);
2253   sw->edSetDefaultNode(n4);
2254   graph->edAddLink(o11,i31);
2255   graph->edAddLink(forEach1->edGetSamplePort(),sw->edGetConditionPort());
2256   graph->edAddLink(o31,n2->edGetInValue1());
2257   graph->edRemoveLink(o31,n2->edGetInValue1());
2258   graph->edAddLink(o31,n2->edGetInValue1());
2259   graph->edAddLink(o31,n2->edGetInValue2());//
2260   graph->edAddLink(o11,i42);
2261   graph->edAddLink(o41,n2->edGetInValue2());
2262   graph->edRemoveLink(o41,n2->edGetInValue2());
2263   graph->edAddLink(o41,n2->edGetInValue2());
2264   graph->edAddLink(o42,n2->edGetInValue1());
2265   int tabI[]={1,2,2,45,2,5,6,2};
2266   vector<int> tabvI(tabI,tabI+8);
2267   SequenceAnyPtr tmp=SequenceAny::New(tabvI);
2268   forEach1->edGetSeqOfSamplesPort()->edInit((Any *)tmp);
2269   //graph->edAddLink(n0->edGetSeqOut(),forEach1->edGetSeqOfSamplesPort());
2270   graph->edAddLink(n0->edGetSeqOut(),n2->edGetInValue2());
2271   Executor exe;
2272   try
2273     {
2274       exe.RunW(graph);
2275       CPPUNIT_ASSERT(false);
2276     }
2277   catch(Exception& e)
2278     {
2279       CPPUNIT_ASSERT(string(e.what())=="InputPort::checkBasicConsistency : Port nbBranches of node with name myFE1 neither initialized nor linked back");
2280     }
2281   forEach1->edGetNbOfBranchesPort()->edInit(7);
2282   //expected vals
2283   int tabI2[]={29,44,44,29,44,29,29,44};
2284   vector<int> tabvI2(tabI2,tabI2+8);
2285   SequenceAnyPtr tmp2=SequenceAny::New(tabvI2);
2286   exe.RunW(graph);
2287   Any *val=n2->edGetSeqOut()->get();
2288   CPPUNIT_ASSERT( *val==*tmp2 );
2289   CPPUNIT_ASSERT_EQUAL(7,(int)forEach1->getNumberOfBranchesCreatedDyn());
2290   exe.RunW(graph);
2291   val=n2->edGetSeqOut()->get();
2292   CPPUNIT_ASSERT( *val==*tmp2 );
2293   CPPUNIT_ASSERT_EQUAL(7,(int)forEach1->getNumberOfBranchesCreatedDyn());
2294   Bloc *graphCloned=(Bloc *)graph->clone(0);
2295   delete graph;
2296   exe.RunW(graphCloned);
2297   val=((Seq2ToyNode *)graphCloned->getChildByName("T2"))->edGetSeqOut()->get();
2298   delete graphCloned;
2299 }
2300
2301 /*!
2302   Test to check possibility to linked several times SamplePort OutputPort of a ForEachLoop node.
2303  */
2304 void EngineIntegrationTest::testForEachLoop5()
2305 {
2306   Bloc *graph=new Bloc("graph");
2307   ForEachLoop *forEach=new ForEachLoop("myFE",Runtime::_tc_double);
2308   graph->edAddChild(forEach);
2309   ToyNode *n1=new ToyNode("T1");
2310   InputPort *i11=n1->edAddInputPort("i11",Runtime::_tc_double); i11->edInit(1.3);
2311   InputPort *i12=n1->edAddInputPort("i12",Runtime::_tc_double); i12->edInit(3.4);
2312   InputPort *i13=n1->edAddInputPort("i13",Runtime::_tc_double); i13->edInit(5.6);
2313   OutputPort *o11=n1->edAddOutputPort("o11",Runtime::_tc_double);
2314   graph->edAddChild(n1);
2315   graph->edAddCFLink(n1,forEach);
2316   SeqToyNode *n2=new SeqToyNode("T2");
2317   graph->edAddChild(n2);
2318   graph->edAddCFLink(n2,forEach);
2319   graph->edAddLink(n1->edGetNbOfInputsOutputPort(),forEach->edGetNbOfBranchesPort());
2320   graph->edAddLink(n2->edGetSeqOut(),forEach->edGetSeqOfSamplesPort());
2321   n2->edGetInIntValue()->edInit(5);
2322   ToyNode *n3=new ToyNode("T3");
2323   InputPort *i31=n3->edAddInputPort("i31",Runtime::_tc_double); 
2324   InputPort *i32=n3->edAddInputPort("i32",Runtime::_tc_double);
2325   OutputPort *o31=n3->edAddOutputPort("o31",Runtime::_tc_double);
2326   forEach->edSetNode(n3);
2327   Seq2ToyNode *n4=new Seq2ToyNode("sequencer");
2328   graph->edAddChild(n4);
2329   graph->edAddCFLink(forEach,n4);
2330   graph->edAddLink(forEach->edGetSamplePort(),i31);
2331   graph->edAddLink(forEach->edGetSamplePort(),i32);
2332   graph->edAddLink(o31,n4->edGetInValue1());
2333   graph->edAddLink(n2->edGetSeqOut(),n4->edGetInValue2());
2334   int tab[]={15,18,21,24,27};
2335   vector<int> tabv(tab,tab+5);
2336   SequenceAnyPtr tmp=SequenceAny::New(tabv);//expected sequence
2337   Executor exe;
2338   exe.RunW(graph);
2339   CPPUNIT_ASSERT_EQUAL(3,(int)forEach->getNumberOfBranchesCreatedDyn());
2340   Any *val=n4->edGetSeqOut()->get();
2341   CPPUNIT_ASSERT( *val==*tmp );
2342   exe.RunW(graph);
2343   CPPUNIT_ASSERT_EQUAL(3,(int)forEach->getNumberOfBranchesCreatedDyn());
2344   n1->edRemovePort(i13);
2345   exe.RunW(graph);
2346   val=n4->edGetSeqOut()->get();
2347   CPPUNIT_ASSERT( *val==*tmp );
2348   CPPUNIT_ASSERT_EQUAL(2,(int)forEach->getNumberOfBranchesCreatedDyn());
2349   exe.RunW(graph);
2350   val=n4->edGetSeqOut()->get();
2351   CPPUNIT_ASSERT( *val==*tmp );
2352   CPPUNIT_ASSERT_EQUAL(2,(int)forEach->getNumberOfBranchesCreatedDyn());
2353   Bloc *graph2=(Bloc *)graph->clone(0);
2354   delete graph;
2355   exe.RunW(graph2);
2356   CPPUNIT_ASSERT_EQUAL(2,(int)((ForEachLoop *)graph2->getChildByName("myFE"))->getNumberOfBranchesCreatedDyn());
2357   exe.RunW(graph2);
2358   CPPUNIT_ASSERT_EQUAL(2,(int)((ForEachLoop *)graph2->getChildByName("myFE"))->getNumberOfBranchesCreatedDyn());
2359   n4=(Seq2ToyNode *)graph2->getChildByName("sequencer");
2360   val=n4->edGetSeqOut()->get();
2361   CPPUNIT_ASSERT( *val==*tmp );
2362   delete graph2;
2363 }
2364
2365 /*!
2366  * Here a test for OptimizerLoop with an evenemential (or synchronous) algorithm
2367  */
2368 void EngineIntegrationTest::testForOptimizerLoop1()
2369 {
2370   Bloc *graph=new Bloc("Global");
2371   OptimizerLoop *opt=new OptimizerLoop("myOptWthAlgSync",".libs/libPluginOptEvTest1","PluginOptEvTest1Factory",true);
2372   graph->edAddChild(opt);
2373   ToyNode *n1=new ToyNode("T1");
2374   ToyNode *n2=new ToyNode("T2");
2375   graph->edAddChild(n2);
2376   graph->edAddCFLink(opt,n2);
2377   opt->edSetNode(n1);
2378   InputPort *i1=n1->edAddInputPort("i1",Runtime::_tc_double);
2379   OutputPort *o1=n1->edAddOutputPort("o1",Runtime::_tc_double);
2380   graph->edAddLink(opt->edGetSamplePort(),i1);
2381   InputPort *i2=n2->edAddInputPort("i2",Runtime::_tc_double);
2382   OutputPort *o2_1=n2->edAddOutputPort("o1",Runtime::_tc_double);
2383   graph->edAddLink(o1,i2);
2384   graph->edAddLink(n1->edGetNbOfInputsOutputPort(),opt->edGetPortForOutPool());
2385   opt->edGetNbOfBranchesPort()->edInit(2);
2386   opt->edGetPortForInitFile()->edInit("toto");
2387   Executor exe;
2388   exe.RunW(graph);
2389   CPPUNIT_ASSERT_DOUBLES_EQUAL(45.6,((OutputToyPort*)o2_1)->get()->getDoubleValue(),DBL_PRECISION_COMPARE );
2390   CPPUNIT_ASSERT(8==(int)opt->getNumberOfEltsConsumed() or 7==(int)opt->getNumberOfEltsConsumed());
2391   CPPUNIT_ASSERT_EQUAL(2,(int)((DynParaLoop *)(opt))->getNumberOfBranchesCreatedDyn());
2392   exe.RunW(graph);
2393   CPPUNIT_ASSERT_DOUBLES_EQUAL(45.6,((OutputToyPort*)o2_1)->get()->getDoubleValue(),DBL_PRECISION_COMPARE );
2394   CPPUNIT_ASSERT(8==(int)opt->getNumberOfEltsConsumed() or 7==(int)opt->getNumberOfEltsConsumed());
2395   CPPUNIT_ASSERT_EQUAL(2,(int)((DynParaLoop *)(opt))->getNumberOfBranchesCreatedDyn());
2396   Bloc *clone=(Bloc *)graph->clone(0);
2397   delete graph;
2398   exe.RunW(clone);
2399   CPPUNIT_ASSERT_DOUBLES_EQUAL(45.6,((OutputToyPort*)(clone->getOutPort("T2.o1")))->get()->getDoubleValue(),DBL_PRECISION_COMPARE );
2400   CPPUNIT_ASSERT(8==(int)((OptimizerLoop *)(clone->getChildByName("myOptWthAlgSync")))->getNumberOfEltsConsumed() or 7==(int)((OptimizerLoop *)(clone->getChildByName("myOptWthAlgSync")))->getNumberOfEltsConsumed());
2401   CPPUNIT_ASSERT_EQUAL(2,(int)((OptimizerLoop *)(clone->getChildByName("myOptWthAlgSync")))->getNumberOfBranchesCreatedDyn());
2402   exe.RunW(clone);
2403   CPPUNIT_ASSERT_DOUBLES_EQUAL(45.6,((OutputToyPort*)(clone->getOutPort("T2.o1")))->get()->getDoubleValue(),DBL_PRECISION_COMPARE );
2404   CPPUNIT_ASSERT(8==(int)((OptimizerLoop *)(clone->getChildByName("myOptWthAlgSync")))->getNumberOfEltsConsumed() or 7==(int)((OptimizerLoop *)(clone->getChildByName("myOptWthAlgSync")))->getNumberOfEltsConsumed());
2405   CPPUNIT_ASSERT_EQUAL(2,(int)((OptimizerLoop *)(clone->getChildByName("myOptWthAlgSync")))->getNumberOfBranchesCreatedDyn());
2406   delete clone;
2407 }
2408
2409
2410 /*!
2411  * Idem testForOptimizerLoop1 but with intermediate bloc inside OptermizerLoop.
2412  */
2413 void EngineIntegrationTest::testForOptimizerLoop2()
2414 {
2415   Bloc *graph=new Bloc("Global");
2416   OptimizerLoop *opt=new OptimizerLoop("myOptWthAlgSync",".libs/libPluginOptEvTest1","PluginOptEvTest1Factory",true);
2417   graph->edAddChild(opt);
2418   ToyNode *n1=new ToyNode("T1");
2419   ToyNode *n2=new ToyNode("T2");
2420   Bloc *bloc=new Bloc("Bloc");
2421   graph->edAddChild(n2);
2422   graph->edAddCFLink(opt,n2);
2423   opt->edSetNode(bloc);
2424   bloc->edAddChild(n1);
2425   InputPort *i1=n1->edAddInputPort("i1",Runtime::_tc_double);
2426   OutputPort *o1=n1->edAddOutputPort("o1",Runtime::_tc_double);
2427   graph->edAddLink(opt->edGetSamplePort(),i1);
2428   InputPort *i2=n2->edAddInputPort("i2",Runtime::_tc_double);
2429   OutputPort *o2_1=n2->edAddOutputPort("o1",Runtime::_tc_double);
2430   graph->edAddLink(o1,i2);
2431   graph->edAddLink(n1->edGetNbOfInputsOutputPort(),opt->edGetPortForOutPool());
2432   opt->edGetNbOfBranchesPort()->edInit(2);
2433   opt->edGetPortForInitFile()->edInit("toto");
2434   Executor exe;
2435   exe.RunW(graph);
2436   CPPUNIT_ASSERT_DOUBLES_EQUAL(45.6,((OutputToyPort*)o2_1)->get()->getDoubleValue(),DBL_PRECISION_COMPARE );
2437   CPPUNIT_ASSERT(8==(int)opt->getNumberOfEltsConsumed() or 7==(int)opt->getNumberOfEltsConsumed());
2438   CPPUNIT_ASSERT_EQUAL(2,(int)((DynParaLoop *)(opt))->getNumberOfBranchesCreatedDyn());
2439   exe.RunW(graph);
2440   CPPUNIT_ASSERT_DOUBLES_EQUAL(45.6,((OutputToyPort*)o2_1)->get()->getDoubleValue(),DBL_PRECISION_COMPARE );
2441   CPPUNIT_ASSERT(8==(int)opt->getNumberOfEltsConsumed() or 7==(int)opt->getNumberOfEltsConsumed());
2442   CPPUNIT_ASSERT_EQUAL(2,(int)((DynParaLoop *)(opt))->getNumberOfBranchesCreatedDyn());
2443   Bloc *clone=(Bloc *)graph->clone(0);
2444   delete graph;
2445   exe.RunW(clone);
2446   CPPUNIT_ASSERT_DOUBLES_EQUAL(45.6,((OutputToyPort*)(clone->getOutPort("T2.o1")))->get()->getDoubleValue(),DBL_PRECISION_COMPARE );
2447   CPPUNIT_ASSERT(8==(int)((OptimizerLoop *)(clone->getChildByName("myOptWthAlgSync")))->getNumberOfEltsConsumed() or 7==(int)((OptimizerLoop *)(clone->getChildByName("Bloc.myOptWthAlgSync")))->getNumberOfEltsConsumed());
2448   CPPUNIT_ASSERT_EQUAL(2,(int)((OptimizerLoop *)(clone->getChildByName("myOptWthAlgSync")))->getNumberOfBranchesCreatedDyn());
2449   exe.RunW(clone);
2450   CPPUNIT_ASSERT_DOUBLES_EQUAL(45.6,((OutputToyPort*)(clone->getOutPort("T2.o1")))->get()->getDoubleValue(),DBL_PRECISION_COMPARE );
2451   CPPUNIT_ASSERT(8==(int)((OptimizerLoop *)(clone->getChildByName("myOptWthAlgSync")))->getNumberOfEltsConsumed() or 7==(int)((OptimizerLoop *)(clone->getChildByName("Bloc.myOptWthAlgSync")))->getNumberOfEltsConsumed());
2452   CPPUNIT_ASSERT_EQUAL(2,(int)((OptimizerLoop *)(clone->getChildByName("myOptWthAlgSync")))->getNumberOfBranchesCreatedDyn());
2453   delete clone;
2454 }
2455
2456 /*!
2457  * Test to check that in for compil-time known connectivity of a graph, deployment calculation is OK. 
2458  */
2459 void EngineIntegrationTest::testForDeployment1()
2460 {
2461   // First test of NON ServiceNodes deployment calculation
2462   ToyNode *n1=new ToyNode("T1");
2463   ToyNode *n2=new ToyNode("T2");
2464   Bloc *graph=new Bloc("Global");
2465   graph->edAddChild(n1); graph->edAddChild(n2);
2466   DeploymentTree tree=graph->getDeploymentTree();
2467   CPPUNIT_ASSERT(tree.isNull());//No placement info
2468   graph->edRemoveChild(n2);
2469   delete n2;
2470   tree=graph->getDeploymentTree();
2471   CPPUNIT_ASSERT(tree.isNull());//No placement info to.
2472   CPPUNIT_ASSERT_EQUAL(0, (int) tree.getNumberOfCTDefContainer()); CPPUNIT_ASSERT_EQUAL(0, (int) tree.getNumberOfRTODefContainer());
2473   CPPUNIT_ASSERT_EQUAL(0, (int) tree.getNumberOfCTDefComponentInstances()); CPPUNIT_ASSERT_EQUAL(0, (int) tree.getNumberOfRTODefComponentInstances());
2474   CPPUNIT_ASSERT(!tree.presenceOfDefaultContainer());
2475   //
2476   ToyNode1S *n1S=new ToyNode1S("T1S"); graph->edAddChild(n1S);
2477   tree=graph->getDeploymentTree();
2478   CPPUNIT_ASSERT(!tree.isNull());//Here placement info.
2479   CPPUNIT_ASSERT_EQUAL( 1, (int) tree.getFreeDeployableTasks().size());
2480   CPPUNIT_ASSERT_EQUAL((Task *)n1S, tree.getFreeDeployableTasks()[0]);
2481   CPPUNIT_ASSERT_EQUAL(0, (int) tree.getNumberOfCTDefContainer()); CPPUNIT_ASSERT_EQUAL(0, (int) tree.getNumberOfRTODefContainer());
2482   CPPUNIT_ASSERT_EQUAL(0, (int) tree.getNumberOfCTDefComponentInstances()); CPPUNIT_ASSERT_EQUAL(0, (int) tree.getNumberOfRTODefComponentInstances());
2483   CPPUNIT_ASSERT(!tree.presenceOfDefaultContainer());
2484   //
2485   Bloc *b1=new Bloc("B1");
2486   ToyNode1S *n2S=new ToyNode1S("T2S"); b1->edAddChild(n2S); ToyNode1S *n3S=new ToyNode1S("T3S"); b1->edAddChild(n3S); ToyNode2S *n4S=new ToyNode2S("T4S");
2487   ToyNode2S *n5S=new ToyNode2S("T5S"); b1->edAddChild(n5S);
2488   graph->edAddChild(b1); graph->edAddChild(n4S);
2489   tree=graph->getDeploymentTree();
2490   CPPUNIT_ASSERT(!tree.isNull());//Here placement info.
2491   CPPUNIT_ASSERT_EQUAL( 5, (int) tree.getFreeDeployableTasks().size());
2492   CPPUNIT_ASSERT_EQUAL(0, (int) tree.getNumberOfCTDefContainer()); CPPUNIT_ASSERT_EQUAL(0, (int) tree.getNumberOfRTODefContainer());
2493   CPPUNIT_ASSERT_EQUAL(0, (int) tree.getNumberOfCTDefComponentInstances()); CPPUNIT_ASSERT_EQUAL(0, (int) tree.getNumberOfRTODefComponentInstances());
2494   CPPUNIT_ASSERT(!tree.presenceOfDefaultContainer());
2495   //Ok now let's associate some components...
2496   ComponentInstanceTest1 *comp1=new ComponentInstanceTest1("FLICA");
2497   n1S->setComponent(comp1);
2498   tree=graph->getDeploymentTree();
2499   CPPUNIT_ASSERT(!tree.isNull());//Here placement info.
2500   CPPUNIT_ASSERT_EQUAL( 4, (int) tree.getFreeDeployableTasks().size());
2501   CPPUNIT_ASSERT_EQUAL(0, (int) tree.getNumberOfCTDefContainer()); CPPUNIT_ASSERT_EQUAL(0, (int) tree.getNumberOfRTODefContainer());
2502   CPPUNIT_ASSERT_EQUAL(1, (int) tree.getNumberOfCTDefComponentInstances()); CPPUNIT_ASSERT_EQUAL(0, (int) tree.getNumberOfRTODefComponentInstances());
2503   CPPUNIT_ASSERT(tree.presenceOfDefaultContainer());
2504   n3S->setComponent(comp1);
2505   tree=graph->getDeploymentTree();
2506   CPPUNIT_ASSERT(!tree.isNull());//Here placement info.
2507   CPPUNIT_ASSERT_EQUAL( 3, (int) tree.getFreeDeployableTasks().size());
2508   CPPUNIT_ASSERT_EQUAL(0, (int) tree.getNumberOfCTDefContainer()); CPPUNIT_ASSERT_EQUAL(0, (int) tree.getNumberOfRTODefContainer());
2509   CPPUNIT_ASSERT_EQUAL(1, (int) tree.getNumberOfCTDefComponentInstances()); CPPUNIT_ASSERT_EQUAL(0, (int) tree.getNumberOfRTODefComponentInstances());
2510   CPPUNIT_ASSERT(tree.presenceOfDefaultContainer());
2511   vector<Task *> ta=tree.getTasksLinkedToComponent(comp1);
2512   set<Task *> setToTest1(ta.begin(),ta.end()); set<Task *> setToTest2; setToTest2.insert(n1S); setToTest2.insert(n3S);
2513   checkSetsEqual(setToTest1,setToTest2);
2514   ComponentInstanceTest1 *comp2=new ComponentInstanceTest1("CRONOS");
2515   n2S->setComponent(comp2);
2516   CPPUNIT_ASSERT_THROW(n4S->setComponent(comp2),YACS::Exception);//incompatibility between ComponentInstanceTest1 and ToyNode2S
2517   tree=graph->getDeploymentTree();
2518   CPPUNIT_ASSERT_EQUAL( 2, (int) tree.getFreeDeployableTasks().size());
2519   CPPUNIT_ASSERT_EQUAL(0, (int) tree.getNumberOfCTDefContainer()); CPPUNIT_ASSERT_EQUAL(0, (int) tree.getNumberOfRTODefContainer());
2520   CPPUNIT_ASSERT_EQUAL(2, (int) tree.getNumberOfCTDefComponentInstances()); CPPUNIT_ASSERT_EQUAL(0, (int) tree.getNumberOfRTODefComponentInstances());
2521   CPPUNIT_ASSERT(tree.presenceOfDefaultContainer());
2522   ComponentInstanceTest2 *comp3=new ComponentInstanceTest2("PYDK");
2523   n4S->setComponent(comp3);
2524   n5S->setComponent(comp3);
2525   tree=graph->getDeploymentTree();
2526   CPPUNIT_ASSERT_EQUAL( 0, (int) tree.getFreeDeployableTasks().size());
2527   CPPUNIT_ASSERT_EQUAL(0, (int) tree.getNumberOfCTDefContainer()); CPPUNIT_ASSERT_EQUAL(0, (int) tree.getNumberOfRTODefContainer());
2528   CPPUNIT_ASSERT_EQUAL(3, (int) tree.getNumberOfCTDefComponentInstances()); CPPUNIT_ASSERT_EQUAL(0, (int) tree.getNumberOfRTODefComponentInstances());
2529   CPPUNIT_ASSERT(tree.presenceOfDefaultContainer());
2530   // Ok let's play with containers now
2531   ContainerTest *cont1=new ContainerTest;
2532   comp1->setContainer(cont1);
2533   tree=graph->getDeploymentTree();
2534   CPPUNIT_ASSERT_EQUAL( 0, (int) tree.getFreeDeployableTasks().size());
2535   CPPUNIT_ASSERT_EQUAL(1, (int) tree.getNumberOfCTDefContainer()); CPPUNIT_ASSERT_EQUAL(0, (int) tree.getNumberOfRTODefContainer());
2536   CPPUNIT_ASSERT_EQUAL(3, (int) tree.getNumberOfCTDefComponentInstances()); CPPUNIT_ASSERT_EQUAL(0, (int) tree.getNumberOfRTODefComponentInstances());
2537   CPPUNIT_ASSERT(tree.presenceOfDefaultContainer());
2538   ContainerTest *cont2=new ContainerTest;
2539   comp2->setContainer(cont2);
2540   tree=graph->getDeploymentTree();
2541   CPPUNIT_ASSERT_EQUAL( 0, (int) tree.getFreeDeployableTasks().size());
2542   CPPUNIT_ASSERT_EQUAL(2, (int) tree.getNumberOfCTDefContainer()); CPPUNIT_ASSERT_EQUAL(0, (int) tree.getNumberOfRTODefContainer());
2543   CPPUNIT_ASSERT_EQUAL(3, (int) tree.getNumberOfCTDefComponentInstances()); CPPUNIT_ASSERT_EQUAL(0, (int) tree.getNumberOfRTODefComponentInstances());
2544   CPPUNIT_ASSERT(tree.presenceOfDefaultContainer());
2545   comp2->setContainer(cont1);
2546   tree=graph->getDeploymentTree();
2547   CPPUNIT_ASSERT_EQUAL( 0, (int) tree.getFreeDeployableTasks().size());
2548   CPPUNIT_ASSERT_EQUAL(1, (int) tree.getNumberOfCTDefContainer()); CPPUNIT_ASSERT_EQUAL(0, (int) tree.getNumberOfRTODefContainer());
2549   CPPUNIT_ASSERT_EQUAL(3, (int) tree.getNumberOfCTDefComponentInstances()); CPPUNIT_ASSERT_EQUAL(0, (int) tree.getNumberOfRTODefComponentInstances());
2550   CPPUNIT_ASSERT(tree.presenceOfDefaultContainer());
2551   ContainerTest2 *cont3=new ContainerTest2;
2552   CPPUNIT_ASSERT_THROW(comp3->setContainer(cont2),YACS::Exception);
2553   comp3->setContainer(cont3);
2554   tree=graph->getDeploymentTree();
2555   vector<Container *> tb=tree.getAllCTDefContainers(); set<Container *> tbs(tb.begin(),tb.end()); set<Container *> tb2;  tb2.insert(cont1); tb2.insert(cont3);
2556   checkSetsEqual(tbs,tb2);
2557   vector<ComponentInstance *> tc=tree.getComponentsLinkedToContainer(cont1); set<ComponentInstance *> tcs(tc.begin(),tc.end());
2558   set<ComponentInstance *> tc2; tc2.insert(comp1); tc2.insert(comp2);
2559   checkSetsEqual(tcs,tc2);
2560   CPPUNIT_ASSERT_EQUAL( 0, (int) tree.getFreeDeployableTasks().size());
2561   CPPUNIT_ASSERT_EQUAL(2, (int) tree.getNumberOfCTDefContainer()); CPPUNIT_ASSERT_EQUAL(0, (int) tree.getNumberOfRTODefContainer());
2562   CPPUNIT_ASSERT_EQUAL(3, (int) tree.getNumberOfCTDefComponentInstances()); CPPUNIT_ASSERT_EQUAL(0, (int) tree.getNumberOfRTODefComponentInstances());
2563   CPPUNIT_ASSERT(!tree.presenceOfDefaultContainer());
2564   ta=tree.getTasksLinkedToComponent(comp1);
2565   //Ok now let's see behaviour on cloning.
2566   Bloc *cl=(Bloc *)graph->clone(0);
2567   tree=cl->getDeploymentTree();
2568   CPPUNIT_ASSERT_EQUAL( 0, (int) tree.getFreeDeployableTasks().size());
2569   CPPUNIT_ASSERT_EQUAL(2, (int) tree.getNumberOfCTDefContainer()); CPPUNIT_ASSERT_EQUAL(0, (int) tree.getNumberOfRTODefContainer());
2570   CPPUNIT_ASSERT_EQUAL(3, (int) tree.getNumberOfCTDefComponentInstances()); CPPUNIT_ASSERT_EQUAL(0, (int) tree.getNumberOfRTODefComponentInstances());
2571   CPPUNIT_ASSERT(!tree.presenceOfDefaultContainer());
2572   tb=tree.getAllCTDefContainers(); tbs.clear(); tbs.insert(tb.begin(),tb.end());
2573   checkSetsNotEqual(tbs,tb2);
2574   delete cl;
2575   //
2576   cont1->attachOnCloning(); cont3->attachOnCloning();
2577   cl=(Bloc *)graph->clone(0);
2578   tree=cl->getDeploymentTree();
2579   CPPUNIT_ASSERT_EQUAL( 0, (int) tree.getFreeDeployableTasks().size());
2580   CPPUNIT_ASSERT_EQUAL(2, (int) tree.getNumberOfCTDefContainer()); CPPUNIT_ASSERT_EQUAL(0, (int) tree.getNumberOfRTODefContainer());
2581   CPPUNIT_ASSERT_EQUAL(3, (int) tree.getNumberOfCTDefComponentInstances()); CPPUNIT_ASSERT_EQUAL(0, (int) tree.getNumberOfRTODefComponentInstances());
2582   CPPUNIT_ASSERT(!tree.presenceOfDefaultContainer());
2583   tb=tree.getAllCTDefContainers(); tbs.clear(); tbs.insert(tb.begin(),tb.end());
2584   checkSetsEqual(tbs,tb2);
2585   delete cl;
2586   //
2587   cont1->dettachOnCloning();
2588   cl=(Bloc *)graph->clone(0);
2589   tree=cl->getDeploymentTree();
2590   CPPUNIT_ASSERT_EQUAL( 0, (int) tree.getFreeDeployableTasks().size());
2591   CPPUNIT_ASSERT_EQUAL(2, (int) tree.getNumberOfCTDefContainer()); CPPUNIT_ASSERT_EQUAL(0, (int) tree.getNumberOfRTODefContainer());
2592   CPPUNIT_ASSERT_EQUAL(3, (int) tree.getNumberOfCTDefComponentInstances()); CPPUNIT_ASSERT_EQUAL(0, (int) tree.getNumberOfRTODefComponentInstances());
2593   CPPUNIT_ASSERT(!tree.presenceOfDefaultContainer());
2594   tb=tree.getAllCTDefContainers(); tbs.clear(); tbs.insert(tb.begin(),tb.end());
2595   CPPUNIT_ASSERT(tbs.find(cont1)==tbs.end());
2596   CPPUNIT_ASSERT(!(tbs.find(cont3)==tbs.end()));
2597   delete cl;
2598   cont1->attachOnCloning();
2599   comp1->attachOnCloning();
2600   comp2->attachOnCloning();
2601   cl=(Bloc *)graph->clone(0);
2602   tree=cl->getDeploymentTree();
2603   CPPUNIT_ASSERT_EQUAL( 0, (int) tree.getFreeDeployableTasks().size());
2604   CPPUNIT_ASSERT_EQUAL(2, (int) tree.getNumberOfCTDefContainer()); CPPUNIT_ASSERT_EQUAL(0, (int) tree.getNumberOfRTODefContainer());
2605   CPPUNIT_ASSERT_EQUAL(3, (int) tree.getNumberOfCTDefComponentInstances()); CPPUNIT_ASSERT_EQUAL(0, (int) tree.getNumberOfRTODefComponentInstances());
2606   CPPUNIT_ASSERT(!tree.presenceOfDefaultContainer());
2607   tc=tree.getComponentsLinkedToContainer(cont1); tcs.clear(); tcs.insert(tc.begin(),tc.end());
2608   checkSetsEqual(tcs,tc2);
2609   delete cl;
2610   comp1->dettachOnCloning();
2611   comp2->dettachOnCloning();
2612   cl=(Bloc *)graph->clone(0);
2613   tree=cl->getDeploymentTree();
2614   CPPUNIT_ASSERT_EQUAL( 0, (int) tree.getFreeDeployableTasks().size());
2615   CPPUNIT_ASSERT_EQUAL(2, (int) tree.getNumberOfCTDefContainer()); CPPUNIT_ASSERT_EQUAL(0, (int) tree.getNumberOfRTODefContainer());
2616   CPPUNIT_ASSERT_EQUAL(3, (int) tree.getNumberOfCTDefComponentInstances()); CPPUNIT_ASSERT_EQUAL(0, (int) tree.getNumberOfRTODefComponentInstances());
2617   CPPUNIT_ASSERT(!tree.presenceOfDefaultContainer());
2618   tc=tree.getComponentsLinkedToContainer(cont1); tcs.clear(); tcs.insert(tc.begin(),tc.end());
2619   checkSetsNotEqual(tcs,tc2);
2620   delete cl;
2621   comp1->attachOnCloning();
2622   cl=(Bloc *)graph->clone(0);
2623   tree=cl->getDeploymentTree();
2624   CPPUNIT_ASSERT_EQUAL( 0, (int) tree.getFreeDeployableTasks().size());
2625   CPPUNIT_ASSERT_EQUAL(2, (int) tree.getNumberOfCTDefContainer()); CPPUNIT_ASSERT_EQUAL(0, (int) tree.getNumberOfRTODefContainer());
2626   CPPUNIT_ASSERT_EQUAL(3, (int) tree.getNumberOfCTDefComponentInstances()); CPPUNIT_ASSERT_EQUAL(0, (int) tree.getNumberOfRTODefComponentInstances());
2627   CPPUNIT_ASSERT(!tree.presenceOfDefaultContainer());
2628   tc=tree.getComponentsLinkedToContainer(cont1); tcs.clear(); tcs.insert(tc.begin(),tc.end());
2629   CPPUNIT_ASSERT(tcs.find(comp1)!=tcs.end());
2630   CPPUNIT_ASSERT(tcs.find(comp2)==tcs.end());
2631   delete cl;
2632   //Final clean up
2633   comp3->decrRef();
2634   comp2->decrRef();
2635   comp1->decrRef();
2636   cont1->decrRef();
2637   cont2->decrRef();
2638   cont3->decrRef();
2639   delete graph;
2640 }
2641
2642 /*!
2643  * Test to check that in for compil-time known connectivity of a graph, deployment calculation is OK. 
2644  */
2645 void EngineIntegrationTest::testForDeployment2()
2646 {
2647   Bloc *graph=new Bloc("graph");
2648   ToyNode1S *n1S=new ToyNode1S("T1S"); graph->edAddChild(n1S);
2649   ForEachLoop *fe1=new ForEachLoop("fe1",Runtime::_tc_double);
2650   Bloc *b1=new Bloc("B1");
2651   fe1->edSetNode(b1);
2652   ToyNode1S *n2S=new ToyNode1S("T2S"); b1->edAddChild(n2S); ToyNode1S *n3S=new ToyNode1S("T3S"); b1->edAddChild(n3S); ToyNode2S *n4S=new ToyNode2S("T4S");
2653   ToyNode2S *n5S=new ToyNode2S("T5S"); b1->edAddChild(n5S);
2654   graph->edAddChild(fe1); graph->edAddChild(n4S);
2655   DeploymentTree tree=graph->getDeploymentTree();
2656   CPPUNIT_ASSERT(!tree.isNull());//Here placement info.
2657   CPPUNIT_ASSERT_EQUAL( 5, (int) tree.getFreeDeployableTasks().size());
2658   CPPUNIT_ASSERT_EQUAL(0, (int) tree.getNumberOfCTDefContainer()); CPPUNIT_ASSERT_EQUAL(0, (int) tree.getNumberOfRTODefContainer());
2659   CPPUNIT_ASSERT_EQUAL(0, (int) tree.getNumberOfCTDefComponentInstances()); CPPUNIT_ASSERT_EQUAL(0, (int) tree.getNumberOfRTODefComponentInstances());
2660   CPPUNIT_ASSERT(!tree.presenceOfDefaultContainer());
2661   //Check that compatibility is checked...
2662   ComponentInstanceTest1 *comp1=new ComponentInstanceTest1("FLICA");
2663   n1S->setComponent(comp1);
2664   CPPUNIT_ASSERT_THROW(n4S->setComponent(comp1),YACS::Exception);//Impossible not compatible between ToyNode1S and ToyNode2S
2665   CPPUNIT_ASSERT_THROW(n2S->setComponent(comp1),YACS::Exception);//Failure here to but due to incompatibility of scopes n2S is in a ForEachLoop and not n1S and comp1 is NOT attached here.
2666   comp1->attachOnCloning();
2667   n2S->setComponent(comp1);//here it's ok because comp1 is attached...
2668   tree=graph->getDeploymentTree();
2669   CPPUNIT_ASSERT(!tree.isNull());
2670   CPPUNIT_ASSERT_EQUAL( 3, (int) tree.getFreeDeployableTasks().size());
2671   CPPUNIT_ASSERT_EQUAL(0, (int) tree.getNumberOfCTDefContainer()); CPPUNIT_ASSERT_EQUAL(0, (int) tree.getNumberOfRTODefContainer());
2672   CPPUNIT_ASSERT_EQUAL(1, (int) tree.getNumberOfCTDefComponentInstances()); CPPUNIT_ASSERT_EQUAL(0, (int) tree.getNumberOfRTODefComponentInstances());
2673   CPPUNIT_ASSERT(tree.presenceOfDefaultContainer());
2674   //Check that RTO (runtime only) components are detected
2675   ComponentInstanceTest1 *comp2=new ComponentInstanceTest1("DKCORE");
2676   n3S->setComponent(comp2);
2677   tree=graph->getDeploymentTree();
2678   CPPUNIT_ASSERT(!tree.isNull());
2679   CPPUNIT_ASSERT_EQUAL( 2, (int) tree.getFreeDeployableTasks().size());
2680   CPPUNIT_ASSERT_EQUAL(0, (int) tree.getNumberOfCTDefContainer()); CPPUNIT_ASSERT_EQUAL(0, (int) tree.getNumberOfRTODefContainer());
2681   CPPUNIT_ASSERT_EQUAL(1, (int) tree.getNumberOfCTDefComponentInstances()); CPPUNIT_ASSERT_EQUAL(1, (int) tree.getNumberOfRTODefComponentInstances());
2682   ComponentInstanceTest2 *comp3=new ComponentInstanceTest2("DKCORE");
2683   n4S->setComponent(comp3);
2684   CPPUNIT_ASSERT_THROW(n5S->setComponent(comp3),YACS::Exception);//For fun just like 19 lines before.
2685   comp3->attachOnCloning();
2686   n5S->setComponent(comp3);//ok
2687   tree=graph->getDeploymentTree();
2688   CPPUNIT_ASSERT(!tree.isNull());
2689   CPPUNIT_ASSERT_EQUAL( 0, (int) tree.getFreeDeployableTasks().size());
2690   CPPUNIT_ASSERT_EQUAL(0, (int) tree.getNumberOfCTDefContainer()); CPPUNIT_ASSERT_EQUAL(0, (int) tree.getNumberOfRTODefContainer());
2691   CPPUNIT_ASSERT_EQUAL(2, (int) tree.getNumberOfCTDefComponentInstances()); CPPUNIT_ASSERT_EQUAL(1, (int) tree.getNumberOfRTODefComponentInstances());
2692   CPPUNIT_ASSERT(tree.presenceOfDefaultContainer());
2693   ContainerTest *cont1=new ContainerTest;
2694   comp1->setContainer(cont1);
2695   tree=graph->getDeploymentTree();
2696   CPPUNIT_ASSERT_EQUAL( 0, (int) tree.getFreeDeployableTasks().size());
2697   CPPUNIT_ASSERT_EQUAL(1, (int) tree.getNumberOfCTDefContainer()); CPPUNIT_ASSERT_EQUAL(0, (int) tree.getNumberOfRTODefContainer());
2698   CPPUNIT_ASSERT_EQUAL(2, (int) tree.getNumberOfCTDefComponentInstances()); CPPUNIT_ASSERT_EQUAL(1, (int) tree.getNumberOfRTODefComponentInstances());
2699   CPPUNIT_ASSERT(tree.presenceOfDefaultContainer());
2700   ContainerTest2 *cont3=new ContainerTest2;
2701   comp3->setContainer(cont3);
2702   tree=graph->getDeploymentTree();
2703   CPPUNIT_ASSERT_EQUAL( 0, (int) tree.getFreeDeployableTasks().size());
2704   CPPUNIT_ASSERT_EQUAL(2, (int) tree.getNumberOfCTDefContainer()); CPPUNIT_ASSERT_EQUAL(0, (int) tree.getNumberOfRTODefContainer());
2705   CPPUNIT_ASSERT_EQUAL(2, (int) tree.getNumberOfCTDefComponentInstances()); CPPUNIT_ASSERT_EQUAL(1, (int) tree.getNumberOfRTODefComponentInstances());
2706   CPPUNIT_ASSERT(tree.presenceOfDefaultContainer());
2707   ContainerTest *cont2=new ContainerTest;
2708   comp2->setContainer(cont2);
2709   tree=graph->getDeploymentTree();
2710   CPPUNIT_ASSERT_EQUAL( 0, (int) tree.getFreeDeployableTasks().size());
2711   CPPUNIT_ASSERT_EQUAL(2, (int) tree.getNumberOfCTDefContainer()); CPPUNIT_ASSERT_EQUAL(1, (int) tree.getNumberOfRTODefContainer());
2712   CPPUNIT_ASSERT_EQUAL(2, (int) tree.getNumberOfCTDefComponentInstances()); CPPUNIT_ASSERT_EQUAL(1, (int) tree.getNumberOfRTODefComponentInstances());
2713   CPPUNIT_ASSERT(!tree.presenceOfDefaultContainer());
2714   vector<Container *> conts=tree.getAllCTDefContainers(); set<Container *> contsS(conts.begin(),conts.end());
2715   set<Container *> expectedContSet; expectedContSet.insert(cont1); expectedContSet.insert(cont3);
2716   checkSetsEqual(expectedContSet,contsS);
2717   conts=tree.getAllRTODefContainers(); contsS.clear(); contsS.insert(conts.begin(),conts.end());
2718   expectedContSet.clear(); expectedContSet.insert(cont2);
2719   checkSetsEqual(expectedContSet,contsS);
2720   cont2->attachOnCloning();
2721   tree=graph->getDeploymentTree();
2722   CPPUNIT_ASSERT_EQUAL( 0, (int) tree.getFreeDeployableTasks().size());
2723   tree.getNumberOfCTDefContainer();
2724   CPPUNIT_ASSERT_EQUAL(3, (int) tree.getNumberOfCTDefContainer()); CPPUNIT_ASSERT_EQUAL(0, (int) tree.getNumberOfRTODefContainer());
2725   CPPUNIT_ASSERT_EQUAL(2, (int) tree.getNumberOfCTDefComponentInstances()); CPPUNIT_ASSERT_EQUAL(1, (int) tree.getNumberOfRTODefComponentInstances());
2726   CPPUNIT_ASSERT(!tree.presenceOfDefaultContainer());
2727   comp2->attachOnCloning();
2728   tree.getNumberOfCTDefContainer();
2729   CPPUNIT_ASSERT_EQUAL(3, (int) tree.getNumberOfCTDefContainer()); CPPUNIT_ASSERT_EQUAL(0, (int) tree.getNumberOfRTODefContainer());
2730   CPPUNIT_ASSERT_EQUAL(3, (int) tree.getNumberOfCTDefComponentInstances()); CPPUNIT_ASSERT_EQUAL(0, (int) tree.getNumberOfRTODefComponentInstances());
2731   CPPUNIT_ASSERT(!tree.presenceOfDefaultContainer());
2732   //clean up
2733   cont1->decrRef();
2734   cont2->decrRef();
2735   cont3->decrRef();
2736   comp1->decrRef();
2737   comp2->decrRef();
2738   comp3->decrRef();
2739   delete graph;
2740 }
2741
2742 /*!
2743  * Checking firstley fondamentals tools for check consistency. Essentially CF dependancy by visiting CF Graph.
2744  * Secondly check that data link at one level is correctly dealed.
2745  */
2746 void EngineIntegrationTest::testForCheckConsistency1()
2747 {
2748   LinkInfo info(LinkInfo::ALL_DONT_STOP);
2749   ToyNode *n1=new ToyNode("T1"); ToyNode *n5=new ToyNode("T5"); ToyNode *n9=new ToyNode("T9");
2750   ToyNode *n2=new ToyNode("T2"); ToyNode *n6=new ToyNode("T6"); ToyNode *n10=new ToyNode("T10");
2751   ToyNode *n3=new ToyNode("T3"); ToyNode *n7=new ToyNode("T7"); ToyNode *n11=new ToyNode("T11");
2752   ToyNode *n4=new ToyNode("T4"); ToyNode *n8=new ToyNode("T8"); ToyNode *n12=new ToyNode("T12");
2753   Bloc *graph=new Bloc("Global");
2754   graph->edAddChild(n1); graph->edAddChild(n2); graph->edAddChild(n3); graph->edAddChild(n4); graph->edAddChild(n5); graph->edAddChild(n6);
2755   graph->edAddChild(n7); graph->edAddChild(n8); graph->edAddChild(n9); graph->edAddChild(n10); graph->edAddChild(n11); graph->edAddChild(n12);
2756   graph->edAddCFLink(n1,n2); graph->edAddCFLink(n1,n4); graph->edAddCFLink(n1,n3); graph->edAddCFLink(n3,n10); graph->edAddCFLink(n4,n6);
2757   graph->edAddCFLink(n2,n10); graph->edAddCFLink(n6,n7); graph->edAddCFLink(n5,n8); graph->edAddCFLink(n9,n6); graph->edAddCFLink(n3,n5);
2758   graph->edAddCFLink(n5,n6); graph->edAddCFLink(n10,n7); graph->edAddCFLink(n10,n11); graph->edAddCFLink(n11,n12);
2759   graph->edAddCFLink(n12,n5);
2760   graph->checkConsistency(info);
2761   CPPUNIT_ASSERT_EQUAL(2,(int)info.getNumberOfInfoLinks(I_CF_USELESS)); CPPUNIT_ASSERT_EQUAL(0,(int)info.getNumberOfWarnLinksGrp(W_ALL));
2762   CPPUNIT_ASSERT_EQUAL(0,(int)info.getNumberOfErrLinks(E_ALL));
2763   set< pair<Node *, Node *> > s=info.getInfoUselessLinks();
2764   set< pair<Node *, Node *> > s2;  s2.insert(pair<Node*,Node*>(n3,n5)); s2.insert(pair<Node*,Node*>(n10,n7));
2765   checkSetsEqual< pair<Node *, Node *> >(s,s2);
2766   set<Node *> s3; set<Node *> setExpected; setExpected.insert(n2); setExpected.insert(n4); setExpected.insert(n3); setExpected.insert(n10);
2767   setExpected.insert(n11); setExpected.insert(n12); setExpected.insert(n5); setExpected.insert(n6); setExpected.insert(n7); setExpected.insert(n8);
2768   map<Node *, set<Node *> > accelStr;
2769   graph->findAllNodesStartingFrom<true>(n1,s3,accelStr,info); accelStr.clear();
2770   checkSetsEqual(setExpected,s3); s3.clear(); setExpected.clear();
2771   graph->findAllNodesStartingFrom<true>(n7,s3,accelStr,info); accelStr.clear();
2772   checkSetsEqual(setExpected,s3); s3.clear(); setExpected.clear();
2773   graph->findAllNodesStartingFrom<false>(n1,s3,accelStr,info); accelStr.clear();
2774   checkSetsEqual(setExpected,s3); s3.clear(); setExpected.clear();
2775   list< vector<Node *> > vec;
2776   graph->findAllPathsStartingFrom<false>(n7, vec,accelStr);
2777   graph->findAllNodesStartingFrom<false>(n7,s3,accelStr,info); accelStr.clear();setExpected=graph->edGetDirectDescendants(); setExpected.erase(n8); setExpected.erase(n7);
2778   checkSetsEqual(setExpected,s3); s3.clear(); setExpected.clear();
2779   //Testing good reinitialisation
2780   setExpected.insert(n2); setExpected.insert(n4); setExpected.insert(n3); setExpected.insert(n10);
2781   setExpected.insert(n11); setExpected.insert(n12); setExpected.insert(n5); setExpected.insert(n6); setExpected.insert(n7); setExpected.insert(n8);
2782   graph->findAllNodesStartingFrom<true>(n1,s3,accelStr,info); accelStr.clear();
2783   checkSetsEqual(setExpected,s3); s3.clear(); setExpected.clear();
2784   graph->findAllNodesStartingFrom<false>(n1,s3,accelStr,info); accelStr.clear();
2785   checkSetsEqual(setExpected,s3); s3.clear(); setExpected.clear();
2786   //End test good reinitialisation
2787   graph->checkConsistency(info);
2788   CPPUNIT_ASSERT_EQUAL(2,(int)info.getNumberOfInfoLinks(I_CF_USELESS)); CPPUNIT_ASSERT_EQUAL(0,(int)info.getNumberOfWarnLinksGrp(W_ALL));
2789   CPPUNIT_ASSERT_EQUAL(0,(int)info.getNumberOfErrLinks(E_ALL));
2790   s=info.getInfoUselessLinks();
2791   s2.clear();  s2.insert(pair<Node*,Node*>(n3,n5)); s2.insert(pair<Node*,Node*>(n10,n7));
2792   checkSetsEqual< pair<Node *, Node *> >(s,s2);
2793   //n3->n5 and n10->n7 have been detected to be useless... try to remove them and relaunch : normally no useless links should be detected
2794   graph->edRemoveCFLink(n3,n5); graph->edRemoveCFLink(n10,n7);
2795   graph->checkConsistency(info);
2796   CPPUNIT_ASSERT_EQUAL(0,(int)info.getNumberOfInfoLinks(I_CF_USELESS)); CPPUNIT_ASSERT_EQUAL(0,(int)info.getNumberOfWarnLinksGrp(W_ALL));
2797   CPPUNIT_ASSERT_EQUAL(0,(int)info.getNumberOfErrLinks(E_ALL));
2798   //Playing with check at one level of scope.
2799   InputPort *i11_1=n11->edAddInputPort("i1",Runtime::_tc_double);
2800   graph->checkConsistency(info);
2801   CPPUNIT_ASSERT_EQUAL(0,(int)info.getNumberOfInfoLinks(I_ALL)); CPPUNIT_ASSERT_EQUAL(0,(int)info.getNumberOfWarnLinksGrp(W_ALL));
2802   CPPUNIT_ASSERT_EQUAL(1,(int)info.getNumberOfErrLinks(E_ALL)); CPPUNIT_ASSERT_EQUAL(1,(int)info.getNumberOfErrLinks(E_ALL));
2803   CPPUNIT_ASSERT_EQUAL(1,(int)info.getNumberOfErrLinks(E_NEVER_SET_INPUTPORT));
2804   pair<OutPort *, InPort *> p1=info.getErrLink(0,E_NEVER_SET_INPUTPORT); pair<OutPort *, InPort *> p2(0,i11_1);
2805   CPPUNIT_ASSERT(p1==p2);
2806   //
2807   i11_1->edInit(3.14);
2808   graph->checkConsistency(info);
2809   CPPUNIT_ASSERT_EQUAL(0,(int)info.getNumberOfInfoLinks(I_ALL)); CPPUNIT_ASSERT_EQUAL(0,(int)info.getNumberOfWarnLinksGrp(W_ALL));
2810   CPPUNIT_ASSERT_EQUAL(0,(int)info.getNumberOfErrLinks(E_ALL));
2811   i11_1->edRemoveManInit();
2812   graph->checkConsistency(info);
2813   CPPUNIT_ASSERT_EQUAL(0,(int)info.getNumberOfInfoLinks(I_ALL)); CPPUNIT_ASSERT_EQUAL(0,(int)info.getNumberOfWarnLinksGrp(W_ALL));
2814   CPPUNIT_ASSERT_EQUAL(1,(int)info.getNumberOfErrLinks(E_ALL)); CPPUNIT_ASSERT_EQUAL(1,(int)info.getNumberOfErrLinks(E_ALL));
2815   CPPUNIT_ASSERT_EQUAL(1,(int)info.getNumberOfErrLinks(E_NEVER_SET_INPUTPORT));
2816   //only back defined
2817   OutputPort *o11_1=n11->edAddOutputPort("o11_1",Runtime::_tc_double);
2818   graph->edAddLink(o11_1,i11_1);
2819   graph->checkConsistency(info);
2820   CPPUNIT_ASSERT_EQUAL(1,(int)info.getNumberOfInfoLinks(I_ALL)); CPPUNIT_ASSERT_EQUAL(1,(int)info.getNumberOfInfoLinks(I_BACK)); CPPUNIT_ASSERT_EQUAL(0,(int)info.getNumberOfWarnLinksGrp(W_ALL));
2821   CPPUNIT_ASSERT_EQUAL(1,(int)info.getNumberOfErrLinks(E_ALL)); CPPUNIT_ASSERT_EQUAL(1,(int)info.getNumberOfErrLinks(E_ONLY_BACKWARD_DEFINED));
2822   graph->edRemoveLink(o11_1,i11_1);
2823   graph->checkConsistency(info);
2824   CPPUNIT_ASSERT_EQUAL(0,(int)info.getNumberOfInfoLinks(I_ALL)); CPPUNIT_ASSERT_EQUAL(0,(int)info.getNumberOfWarnLinksGrp(W_ALL));
2825   CPPUNIT_ASSERT_EQUAL(1,(int)info.getNumberOfErrLinks(E_ALL)); CPPUNIT_ASSERT_EQUAL(1,(int)info.getNumberOfErrLinks(E_ALL));
2826   CPPUNIT_ASSERT_EQUAL(1,(int)info.getNumberOfErrLinks(E_NEVER_SET_INPUTPORT));
2827   //
2828   OutputPort *o10_1=n10->edAddOutputPort("o10_1",Runtime::_tc_double);
2829   graph->edAddLink(o10_1,i11_1);
2830   graph->checkConsistency(info);
2831   CPPUNIT_ASSERT_EQUAL(0,(int)info.getNumberOfInfoLinks(I_ALL)); CPPUNIT_ASSERT_EQUAL(0,(int)info.getNumberOfWarnLinksGrp(W_ALL));
2832   CPPUNIT_ASSERT_EQUAL(0,(int)info.getNumberOfErrLinks(E_ALL));
2833   OutputPort *o2_1=n2->edAddOutputPort("o2_1",Runtime::_tc_double);
2834   graph->edAddLink(o2_1,i11_1);
2835   // useless
2836   graph->checkConsistency(info);
2837   CPPUNIT_ASSERT_EQUAL(1,(int)info.getNumberOfInfoLinks(I_ALL)); CPPUNIT_ASSERT_EQUAL(1,(int)info.getNumberOfInfoLinks(I_USELESS)); CPPUNIT_ASSERT_EQUAL(0,(int)info.getNumberOfWarnLinksGrp(W_ALL));
2838   CPPUNIT_ASSERT_EQUAL(0,(int)info.getNumberOfErrLinks(E_ALL));
2839   // many useless
2840   OutputPort *o1_1=n1->edAddOutputPort("o1_1",Runtime::_tc_double);
2841   graph->edAddLink(o1_1,i11_1);
2842   graph->checkConsistency(info);
2843   CPPUNIT_ASSERT_EQUAL(1,(int)info.getNumberOfInfoLinks(I_ALL)); CPPUNIT_ASSERT_EQUAL(2,(int)info.getNumberOfInfoLinks(I_USELESS)); CPPUNIT_ASSERT_EQUAL(0,(int)info.getNumberOfWarnLinksGrp(W_ALL));
2844   CPPUNIT_ASSERT_EQUAL(0,(int)info.getNumberOfErrLinks(E_ALL));
2845   // collapse and useless ; useless
2846   OutputPort *o3_1=n3->edAddOutputPort("o3_1",Runtime::_tc_double);
2847   graph->edAddLink(o3_1,i11_1);
2848   graph->checkConsistency(info);
2849   CPPUNIT_ASSERT_EQUAL(1,(int)info.getNumberOfInfoLinks(I_ALL)); CPPUNIT_ASSERT_EQUAL(1,(int)info.getNumberOfInfoLinks(I_USELESS)); CPPUNIT_ASSERT_EQUAL(1,(int)info.getNumberOfWarnLinksGrp(W_ALL));
2850   CPPUNIT_ASSERT_EQUAL(0,(int)info.getNumberOfErrLinks(E_ALL)); CPPUNIT_ASSERT_EQUAL(1,(int)info.getNumberOfWarnLinksGrp(W_COLLAPSE_AND_USELESS));
2851   // collapse ; useless
2852   graph->edRemoveLink(o10_1,i11_1);
2853   graph->checkConsistency(info);
2854   CPPUNIT_ASSERT_EQUAL(1,(int)info.getNumberOfInfoLinks(I_ALL)); CPPUNIT_ASSERT_EQUAL(1,(int)info.getNumberOfInfoLinks(I_USELESS)); CPPUNIT_ASSERT_EQUAL(1,(int)info.getNumberOfWarnLinksGrp(W_ALL));
2855   CPPUNIT_ASSERT_EQUAL(0,(int)info.getNumberOfErrLinks(E_ALL)); CPPUNIT_ASSERT_EQUAL(1,(int)info.getNumberOfWarnLinksGrp(W_COLLAPSE));
2856   // collapse ; useless ; unpredictable'
2857   OutputPort *o4_1=n4->edAddOutputPort("o4_1",Runtime::_tc_double);
2858   graph->edAddLink(o4_1,i11_1);
2859   graph->checkConsistency(info);
2860   CPPUNIT_ASSERT_EQUAL(1,(int)info.getNumberOfInfoLinks(I_ALL)); CPPUNIT_ASSERT_EQUAL(1,(int)info.getNumberOfInfoLinks(I_USELESS)); CPPUNIT_ASSERT_EQUAL(1,(int)info.getNumberOfWarnLinksGrp(W_ALL));
2861   CPPUNIT_ASSERT_EQUAL(1,(int)info.getNumberOfErrLinks(E_ALL)); CPPUNIT_ASSERT_EQUAL(1,(int)info.getNumberOfErrLinks(E_UNPREDICTABLE_FED)); CPPUNIT_ASSERT_EQUAL(1,(int)info.getNumberOfWarnLinksGrp(W_COLLAPSE));
2862   CPPUNIT_ASSERT( (pair<OutPort*,InPort *>(o4_1,i11_1)==info.getErrLink(0,E_UNPREDICTABLE_FED)) );
2863   // restart all
2864   graph->edRemoveLink(o3_1,i11_1); graph->edRemoveLink(o4_1,i11_1); graph->edRemoveLink(o1_1,i11_1);
2865   graph->checkConsistency(info);
2866   CPPUNIT_ASSERT_EQUAL(0,(int)info.getNumberOfInfoLinks(I_ALL)); CPPUNIT_ASSERT_EQUAL(0,(int)info.getNumberOfWarnLinksGrp(W_ALL)); CPPUNIT_ASSERT_EQUAL(0,(int)info.getNumberOfErrLinks(E_ALL));
2867   // back link 
2868   OutputPort *o5_1=n5->edAddOutputPort("o5_1",Runtime::_tc_double); graph->edAddLink(o5_1,i11_1);
2869   graph->checkConsistency(info);
2870   CPPUNIT_ASSERT_EQUAL(1,(int)info.getNumberOfInfoLinks(I_ALL)); CPPUNIT_ASSERT_EQUAL(0,(int)info.getNumberOfWarnLinksGrp(W_ALL)); CPPUNIT_ASSERT_EQUAL(0,(int)info.getNumberOfErrLinks(E_ALL));
2871   CPPUNIT_ASSERT_EQUAL(1,(int)info.getNumberOfInfoLinks(I_BACK));
2872   CPPUNIT_ASSERT( (pair<OutPort*,InPort *>(o5_1,i11_1)==info.getInfoLink(0,I_BACK)) );
2873   // back - useless link
2874   OutputPort *o12_1=n12->edAddOutputPort("o12_1",Runtime::_tc_double); graph->edAddLink(o12_1,i11_1);
2875   graph->checkConsistency(info);
2876   CPPUNIT_ASSERT_EQUAL(2,(int)info.getNumberOfInfoLinks(I_ALL)); CPPUNIT_ASSERT_EQUAL(0,(int)info.getNumberOfWarnLinksGrp(W_ALL)); CPPUNIT_ASSERT_EQUAL(0,(int)info.getNumberOfErrLinks(E_ALL));
2877   CPPUNIT_ASSERT_EQUAL(1,(int)info.getNumberOfInfoLinks(I_BACK)); CPPUNIT_ASSERT_EQUAL(1,(int)info.getNumberOfInfoLinks(I_BACK_USELESS));
2878   CPPUNIT_ASSERT( (pair<OutPort*,InPort *>(o5_1,i11_1)==info.getInfoLink(0,I_BACK)) );
2879   CPPUNIT_ASSERT( (pair<OutPort*,InPort *>(o12_1,i11_1)==info.getInfoLink(0,I_BACK_USELESS)) );
2880   graph->edAddLink(o11_1,i11_1);
2881   graph->checkConsistency(info);
2882   CPPUNIT_ASSERT_EQUAL(2,(int)info.getNumberOfInfoLinks(I_ALL)); CPPUNIT_ASSERT_EQUAL(0,(int)info.getNumberOfWarnLinksGrp(W_ALL)); CPPUNIT_ASSERT_EQUAL(0,(int)info.getNumberOfErrLinks(E_ALL));
2883   CPPUNIT_ASSERT_EQUAL(1,(int)info.getNumberOfInfoLinks(I_BACK)); CPPUNIT_ASSERT_EQUAL(2,(int)info.getNumberOfInfoLinks(I_BACK_USELESS));
2884   delete graph;
2885 }
2886
2887 void EngineIntegrationTest::testForCheckConsistency2()
2888 {
2889   LinkInfo info(LinkInfo::ALL_DONT_STOP);
2890   Bloc *graph=new Bloc("Global");
2891   ToyNode *n1=new ToyNode("T1"); ToyNode *n5=new ToyNode("T5"); ToyNode *n9=new ToyNode("T9");
2892   ToyNode *n2=new ToyNode("T2"); ToyNode *n6=new ToyNode("T6"); ToyNode *n10=new ToyNode("T10");
2893   ToyNode *n3=new ToyNode("T3"); ToyNode *n7=new ToyNode("T7"); ToyNode *n11=new ToyNode("T11");
2894   ToyNode *n4=new ToyNode("T4"); ToyNode *n8=new ToyNode("T8"); ToyNode *n12=new ToyNode("T12");
2895   graph->edAddChild(n1); graph->edAddChild(n2); graph->edAddChild(n3); graph->edAddChild(n4); graph->edAddChild(n5); graph->edAddChild(n6);
2896   graph->edAddChild(n7); graph->edAddChild(n8); graph->edAddChild(n9); graph->edAddChild(n10); graph->edAddChild(n11); graph->edAddChild(n12);
2897   graph->edAddCFLink(n1,n10); 
2898   graph->edAddCFLink(n10,n8); graph->edAddCFLink(n8,n7); graph->edAddCFLink(n10,n7); graph->edAddCFLink(n1,n3);
2899   graph->checkConsistency(info);
2900   set< pair<Node *, Node *> > s=info.getInfoUselessLinks(); set< pair<Node *, Node *> > s2;  s2.insert(pair<Node*,Node*>(n10,n7));
2901   checkSetsEqual< pair<Node *, Node *> >(s,s2);
2902   set<Node *> s3; set<Node *> setExpected; map<Node *, set<Node *> > accelStr;
2903   graph->findAllNodesStartingFrom<true>(n1,s3,accelStr,info); accelStr.clear();
2904   delete graph;
2905 }