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
26 class TestEdit(unittest.TestCase):
29 SALOMERuntime.RuntimeSALOME_setRuntime()
30 self.r = pilot.getRuntime()
31 self.l = loader.YACSLoader()
32 self.e = pilot.ExecutorSwig()
36 p = self.r.createProc("pr")
38 t=p.getTypeCode("double")
42 td=p.createType("double","double")
43 ti=p.createType("int","int")
44 tc1=p.createInterfaceTc("","Obj",[])
45 print tc1.name(),tc1.id()
46 tc2=p.createInterfaceTc("","Obj2",[tc1])
47 print tc2.name(),tc2.id()
48 tc3=p.createSequenceTc("","seqdbl",td)
49 print tc3.name(),tc3.id(),tc3.contentType()
50 tc4=p.createSequenceTc("","seqObj2",tc2)
51 tc5=p.createSequenceTc("","seqint",ti)
52 print tc4.name(),tc4.id()
57 print td.isAdaptable(ti),1
58 print ti.isAdaptable(td),0
59 print tc5.isAdaptable(tc3),0
60 print tc3.isAdaptable(tc5),1
62 n=self.r.createScriptNode("","node1")
63 n.setScript("print 'coucou1'")
64 n.edAddInputPort("p1",ti)
65 n.edAddOutputPort("p1",ti)
67 inport=n.getInputPort("p1");
70 inport.edInitXML("<value><intt>5</int></value>")
71 except ValueError, ex:
72 print "Value Error: ", ex
74 except pilot.Exception,ex:
75 print "YACS exception:",ex.what()
77 self.assert_(retex is not None, "exception not raised, or wrong type")
78 inport.edInitXML("<value><int>5</int></value>")
80 # --- create script node node2
81 n2=self.r.createScriptNode("","node2")
82 n2.setScript("print 'coucou2'")
83 n2.edAddInputPort("p1",ti)
87 # --- control link between nodes n and n2
89 # --- end control link
91 # --- datalink between ports p1 of nodes n1 and n2
92 p.edAddLink(n.getOutputPort("p1"),n2.getInputPort("p1"))
95 n=self.r.createFuncNode("","node3")
103 n4=self.r.createRefNode("","node4")
104 n4.setRef("corbaname:rir:#test.my_context/Echo.Object")
105 n4.setMethod("echoDouble")
106 n4.edAddInputDataStreamPort("pin",ti)
107 n4.edAddOutputDataStreamPort("pout",ti)
110 n5=self.r.createRefNode("","node5")
111 n5.setRef("corbaname:rir:#test.my_context/Echo.Object")
112 n5.setMethod("echoDouble")
113 n5.edAddInputDataStreamPort("pin",ti)
114 n5.edAddOutputDataStreamPort("pout",ti)
117 p.edAddLink(n4.getOutputDataStreamPort("pout"),n5.getInputDataStreamPort("pin"))
119 #n=self.r.createCompoNode("","node5")
121 #n.setMethod("makeBanner")
124 # --- create a bloc with one node
125 b=self.r.createBloc("b1")
128 n=self.r.createScriptNode("","b1.node2")
129 n.setScript("print 'coucou2'")
133 # --- create a for loop with one node
134 lo=self.r.createForLoop("l1")
136 ip=lo.edGetNbOfTimesInputPort()
139 n=self.r.createScriptNode("","l1.node2")
140 n.setScript("print 'coucou2'")
144 # --- control link between bloc b1 and loop l1
146 # --- end control link
148 # --- create a while loop with one node
149 wh=self.r.createWhileLoop("w1")
151 n=self.r.createFuncNode("","w1.node3")
158 n.edAddOutputPort("p1",ti)
160 cport=wh.edGetConditionPort()
161 cport.edInitBool(True)
163 p.edAddLink(n.getOutputPort("p1"),wh.getInputPort("condition")) #or cport
165 # --- create a switch
166 sw=self.r.createSwitch("sw1")
168 n=self.r.createFuncNode("","sw1.node3")
175 n.edAddOutputPort("p1",ti)
177 n=self.r.createFuncNode("","sw1.node4")
184 n.edAddOutputPort("p1",ti)
185 sw.edSetDefaultNode(n)
186 sw.edGetConditionPort().edInitInt(1)
191 except pilot.Exception,ex:
195 #self.e.displayDot(p)
198 if __name__ == '__main__':
200 U = os.getenv('USER')
201 f=open("/tmp/" + U + "/UnitTestsResult", 'a')
202 f.write(" --- TEST src/yacsloader: testEdit.py\n")
203 suite = unittest.makeSuite(TestEdit)
204 result=unittest.TextTestRunner(f, descriptions=1, verbosity=1).run(suite)
206 sys.exit(not result.wasSuccessful())