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