2 // --- include from engine first, to avoid redifinition warning _POSIX_C_SOURCE
5 #include "ElementaryNode.hxx"
10 #include "engineTest.hxx"
18 using namespace YACS::ENGINE;
24 #define MYDEBTRACE {std::cerr << __FILE__ << " [" << __LINE__ << "] : ";}
25 #define DEBTRACE(msg) {MYDEBTRACE; std::cerr<<msg<<std::endl<<std::flush;}
31 map<string, Node*> EngineTest::_nodeMap;
32 map<string, ComposedNode*> EngineTest::_compoMap;
36 TypeCode *EngineTest::_tc_bool = new TypeCode(Bool);
37 TypeCode *EngineTest::_tc_int = new TypeCode(Int);
38 TypeCode *EngineTest::_tc_double = new TypeCode(Double);
41 void EngineTest::setUp()
45 void EngineTest::tearDown()
49 void EngineTest::checkGetRuntime()
51 CPPUNIT_ASSERT_THROW(Runtime *myrun = getRuntime(), YACS::Exception);
52 Runtime::setRuntime();
53 Runtime *myrun1 = getRuntime();
54 CPPUNIT_ASSERT(myrun1);
55 Runtime *myrun2 = getRuntime();
56 CPPUNIT_ASSERT_EQUAL(myrun1, myrun2);
59 void EngineTest::checkInGateOutGate()
61 string nodeName = "Node1";
62 ElementaryNode* node1 = new TestElemNode(nodeName);
63 _nodeMap[nodeName] = node1;
66 ElementaryNode* node2 = new TestElemNode(nodeName);
67 _nodeMap[nodeName] = node2;
69 DEBTRACE(" --- check InGate OK after node creation" );
71 InGate *node1Ingate = node1->getInGate();
72 CPPUNIT_ASSERT(node1Ingate);
73 string name=node1Ingate->getNameOfTypeOfCurrentInstance();
74 string expected="InGate";
75 CPPUNIT_ASSERT_EQUAL(name,expected);
78 DEBTRACE(" --- check OutGate OK after node creation" );
80 OutGate *node1Outgate = node1->getOutGate();
81 CPPUNIT_ASSERT(node1Outgate);
82 string name=node1Outgate->getNameOfTypeOfCurrentInstance();
83 string expected="OutGate";
84 CPPUNIT_ASSERT_EQUAL(name,expected);
88 void EngineTest::checkNodePortNumber()
90 ElementaryNode* node1 = (ElementaryNode*) _nodeMap["Node1"];
92 DEBTRACE(" --- check number of ports = 0 after node creation" );
93 CPPUNIT_ASSERT(node1->getNumberOfInputPorts() == 0);
94 CPPUNIT_ASSERT(node1->getNumberOfOutputPorts() == 0);
96 InputPort *in1 = node1->edAddInputPort("ib1",_tc_bool);
97 InputPort *in2 = node1->edAddInputPort("ii1",_tc_int);
98 InputPort *in3 = node1->edAddInputPort("ii2",_tc_int);
99 InputPort *in4 = node1->edAddInputPort("id1",_tc_double);
101 OutputPort *ou1 = node1->edAddOutputPort("ob1",_tc_bool);
102 OutputPort *ou2 = node1->edAddOutputPort("oi1",_tc_int);
103 OutputPort *ou3 = node1->edAddOutputPort("od1",_tc_double);
105 DEBTRACE(" --- check number of ports after ports creation" );
106 // DEBTRACE(" node1->getNumberOfInputPorts(): "
107 // << node1->getNumberOfInputPorts());
108 // DEBTRACE(" node1->getNumberOfOutputPorts(): "
109 // << node1->getNumberOfOutputPorts());
110 CPPUNIT_ASSERT(node1->getNumberOfInputPorts() == 4);
111 CPPUNIT_ASSERT(node1->getNumberOfOutputPorts() == 3);
114 void EngineTest::checkPortTypeName()
116 ElementaryNode* node1 = (ElementaryNode*) _nodeMap["Node1"];
118 DEBTRACE(" --- check InputPort name OK" );
120 string name=node1->getInputPort("ib1")->NAME;
121 string expected="InputPort";
122 CPPUNIT_ASSERT_EQUAL(name,expected);
125 DEBTRACE(" --- check OutputPort name OK" );
127 string name=node1->getOutputPort("ob1")->NAME;
128 string expected="OutputPort";
129 CPPUNIT_ASSERT_EQUAL(name,expected);
133 void EngineTest::checkDuplicatePortName()
135 ElementaryNode* node1 = (ElementaryNode*) _nodeMap["Node1"];
136 DEBTRACE(" --- check duplicated name throws exception" );
137 CPPUNIT_ASSERT_THROW(InputPort *in5=node1->edAddInputPort("ii2",_tc_int),
141 void EngineTest::checkRemovePort()
143 ElementaryNode* node1 = (ElementaryNode*) _nodeMap["Node1"];
144 ElementaryNode* node2 = (ElementaryNode*) _nodeMap["Node2"];
146 DEBTRACE(" --- check remove port" );
148 node1->edRemovePort(node1->getInputPort("ib1"));
149 CPPUNIT_ASSERT(node1->getNumberOfInputPorts() == 3);
150 CPPUNIT_ASSERT(node1->getNumberOfOutputPorts() == 3);
153 DEBTRACE(" --- check remove wrong port throws exception" )
155 CPPUNIT_ASSERT_THROW(node1->edRemovePort(node1->getInputPort("ib1")),
160 void EngineTest::checkAddNodesToBloc()
162 DEBTRACE(" --- delete node; // ====== NOT OK : done by bloc" );
164 for (int i=0; i<10; i++)
169 ElementaryNode* node = new TestElemNode(s);
171 InputPort *i1 = node->edAddInputPort("ib1",_tc_bool);
172 InputPort *i2 = node->edAddInputPort("ii1",_tc_int);
173 InputPort *i3 = node->edAddInputPort("ii2",_tc_int);
174 InputPort *i4 = node->edAddInputPort("id1",_tc_double);
175 OutputPort *o1 = node->edAddOutputPort("ob1",_tc_bool);
176 OutputPort *o2 = node->edAddOutputPort("oi1",_tc_int);
177 OutputPort *o3 = node->edAddOutputPort("od1",_tc_double);
180 DEBTRACE(" --- create bloc, add two nodes, check constituants" );
182 Bloc* bloc1 = new Bloc("bloc1");
183 _nodeMap["bloc1"] = bloc1;
184 _compoMap["bloc1"] = bloc1;
185 bloc1->edAddChild(_nodeMap["Node_1"]);
186 bloc1->edAddChild(_nodeMap["Node_2"]);
188 set<ElementaryNode *> setelem = bloc1->getRecursiveConstituents();
189 CPPUNIT_ASSERT(setelem.size() == 2);
193 void EngineTest::checkAddingTwiceSameNodeInSameBloc()
195 DEBTRACE(" --- add the same node two times does nothing: return false" );
197 CPPUNIT_ASSERT(! ((Bloc*)_compoMap["bloc1"])->edAddChild(_nodeMap["Node_1"]));
200 void EngineTest::checkAddingTwiceSameNodeInTwoBlocs()
202 DEBTRACE(" --- add a node already used elsewhere raises exception" );
204 Bloc* bloc2 = new Bloc("bloc2");
205 _nodeMap["bloc2"] = bloc2;
206 _compoMap["bloc2"] = bloc2;
207 bloc2->edAddChild(_nodeMap["Node_3"]);
209 CPPUNIT_ASSERT_THROW(bloc2->edAddChild(_nodeMap["Node_1"]),
213 void EngineTest::checkRecursiveBlocs_NumberOfNodes()
215 Bloc *bloc1 = (Bloc*)_compoMap["bloc1"];
216 Bloc *bloc2 = (Bloc*)_compoMap["bloc2"];
218 DEBTRACE(" --- recursive blocs, check constituants" );
220 Bloc* bloc3 = new Bloc("bloc3");
221 _nodeMap["bloc3"] = bloc3;
222 _compoMap["bloc3"] = bloc3;
223 bloc3->edAddChild((bloc1)); // 2 elementary nodes
224 bloc3->edAddChild((bloc2)); // 1 elementary node
225 bloc3->edAddChild(_nodeMap["Node_4"]); // 1 elementary node
227 set<ElementaryNode *> setelem = bloc3->getRecursiveConstituents();
228 CPPUNIT_ASSERT(setelem.size() == 4);
229 for (set<ElementaryNode*>::iterator it=setelem.begin(); it!=setelem.end(); it++)
231 DEBTRACE(" elem name = " << (*it)->getName());
236 void EngineTest::checkRecursiveBlocs_NumberOfPorts()
238 Bloc *bloc3 = (Bloc*)_compoMap["bloc3"];
240 DEBTRACE(" --- recursive blocs, check input & output ports // COMPLETER" );
241 CPPUNIT_ASSERT(bloc3->getNumberOfInputPorts() == 4*4);
242 DEBTRACE(" number of input ports: " << bloc3->getNumberOfInputPorts());
243 DEBTRACE(" number of output ports: " << bloc3->getNumberOfOutputPorts());
245 set<InputPort *> inset = bloc3->getSetOfInputPort();
246 set<OutputPort *> outset = bloc3->getSetOfOutputPort();
247 for (set<InputPort *>::iterator it=inset.begin(); it!=inset.end(); it++)
249 DEBTRACE(" input port name = " << bloc3->getInputPortName(*it));
251 for (set<OutputPort *>::iterator it=outset.begin(); it!=outset.end(); it++)
253 DEBTRACE(" output port name = " << (*it)->getName());
258 void EngineTest::checkPortNameInBloc()
261 DEBTRACE(" --- recursive blocs, check port names" );
263 InputPort *inport = _nodeMap["Node_1"]->getInputPort("id1");
264 CPPUNIT_ASSERT(_nodeMap["bloc3"]->getInputPortName(inport) == "bloc1.Node_1.id1");
267 void EngineTest::checkGetNameOfPortNotInBloc()
269 InputPort *inport = _nodeMap["Node_5"]->getInputPort("id1");
270 CPPUNIT_ASSERT_THROW(string name = _nodeMap["bloc3"]->getInputPortName(inport),
274 void EngineTest::RecursiveBlocs_multipleRecursion()
277 Bloc* bloc = new Bloc("bloc4");
278 _nodeMap["bloc4"] = bloc;
279 _compoMap["bloc4"] = bloc;
280 bloc->edAddChild(_nodeMap["Node_5"]);
281 bloc->edAddChild(_nodeMap["Node_6"]);
285 Bloc* bloc = new Bloc("bloc5");
286 _nodeMap["bloc5"] = bloc;
287 _compoMap["bloc5"] = bloc;
288 bloc->edAddChild(_nodeMap["Node_7"]);
289 bloc->edAddChild(_nodeMap["Node_8"]);
293 Bloc* bloc = new Bloc("bloc6");
294 _nodeMap["bloc6"] = bloc;
295 _compoMap["bloc6"] = bloc;
296 bloc->edAddChild(_nodeMap["bloc4"]);
297 bloc->edAddChild(_nodeMap["bloc5"]);
301 Bloc* bloc = new Bloc("bloc7");
302 _nodeMap["bloc7"] = bloc;
303 _compoMap["bloc7"] = bloc;
304 bloc->edAddChild(_nodeMap["bloc3"]);
305 bloc->edAddChild(_nodeMap["bloc6"]);
309 Bloc* bloc = new Bloc("graphe");
310 _nodeMap["graphe"] = bloc;
311 _compoMap["graphe"] = bloc;
312 bloc->edAddChild(_nodeMap["bloc7"]);
313 bloc->edAddChild(_nodeMap["Node_9"]);
317 set<ElementaryNode *> setelem = _nodeMap["graphe"]->getRecursiveConstituents();
318 CPPUNIT_ASSERT(setelem.size() == 9);
319 for (set<ElementaryNode*>::iterator it=setelem.begin(); it!=setelem.end(); it++)
321 DEBTRACE(" elem name = " << (*it)->getName());
326 set<InputPort *> inset = _nodeMap["bloc7"]->getSetOfInputPort();
327 set<OutputPort *> outset = _nodeMap["bloc7"]->getSetOfOutputPort();
328 for (set<InputPort *>::iterator it=inset.begin(); it!=inset.end(); it++)
330 DEBTRACE(" input port name for bloc7 = " << _nodeMap["bloc7"]->getInputPortName(*it));
331 DEBTRACE(" input port name for graphe = " << _nodeMap["graphe"]->getInputPortName(*it));
333 for (set<OutputPort *>::iterator it=outset.begin(); it!=outset.end(); it++)
335 DEBTRACE(" output port name = " << (*it)->getName());