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