1 # Copyright (C) 2006-2008 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.
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
25 class TestEdit(unittest.TestCase):
28 SALOMERuntime.RuntimeSALOME_setRuntime()
29 self.r = pilot.getRuntime()
30 self.l = loader.YACSLoader()
31 self.e = pilot.ExecutorSwig()
35 p = self.r.createProc("pr")
37 t=p.getTypeCode("double")
41 td=p.createType("double","double")
42 ti=p.createType("int","int")
43 tc1=p.createInterfaceTc("","Obj",[])
44 print tc1.name(),tc1.id()
45 tc2=p.createInterfaceTc("","Obj2",[tc1])
46 print tc2.name(),tc2.id()
47 tc3=p.createSequenceTc("","seqdbl",td)
48 print tc3.name(),tc3.id(),tc3.contentType()
49 tc4=p.createSequenceTc("","seqObj2",tc2)
50 tc5=p.createSequenceTc("","seqint",ti)
51 print tc4.name(),tc4.id()
56 print td.isAdaptable(ti),1
57 print ti.isAdaptable(td),0
58 print tc5.isAdaptable(tc3),0
59 print tc3.isAdaptable(tc5),1
61 n=self.r.createScriptNode("","node1")
62 n.setScript("print 'coucou1'")
63 n.edAddInputPort("p1",ti)
64 n.edAddOutputPort("p1",ti)
66 inport=n.getInputPort("p1");
69 inport.edInitXML("<value><intt>5</int></value>")
70 except ValueError, ex:
71 print "Value Error: ", ex
73 except pilot.Exception,ex:
74 print "YACS exception:",ex.what()
76 self.assert_(retex is not None, "exception not raised, or wrong type")
77 inport.edInitXML("<value><int>5</int></value>")
79 # --- create script node node2
80 n2=self.r.createScriptNode("","node2")
81 n2.setScript("print 'coucou2'")
82 n2.edAddInputPort("p1",ti)
86 # --- control link between nodes n and n2
88 # --- end control link
90 # --- datalink between ports p1 of nodes n1 and n2
91 p.edAddLink(n.getOutputPort("p1"),n2.getInputPort("p1"))
94 n=self.r.createFuncNode("","node3")
102 n4=self.r.createRefNode("","node4")
103 n4.setRef("corbaname:rir:#test.my_context/Echo.Object")
104 n4.setMethod("echoDouble")
105 n4.edAddInputDataStreamPort("pin",ti)
106 n4.edAddOutputDataStreamPort("pout",ti)
109 n5=self.r.createRefNode("","node5")
110 n5.setRef("corbaname:rir:#test.my_context/Echo.Object")
111 n5.setMethod("echoDouble")
112 n5.edAddInputDataStreamPort("pin",ti)
113 n5.edAddOutputDataStreamPort("pout",ti)
116 p.edAddLink(n4.getOutputDataStreamPort("pout"),n5.getInputDataStreamPort("pin"))
118 #n=self.r.createCompoNode("","node5")
120 #n.setMethod("makeBanner")
123 # --- create a bloc with one node
124 b=self.r.createBloc("b1")
127 n=self.r.createScriptNode("","b1.node2")
128 n.setScript("print 'coucou2'")
132 # --- create a for loop with one node
133 lo=self.r.createForLoop("l1")
135 ip=lo.edGetNbOfTimesInputPort()
138 n=self.r.createScriptNode("","l1.node2")
139 n.setScript("print 'coucou2'")
143 # --- control link between bloc b1 and loop l1
145 # --- end control link
147 # --- create a while loop with one node
148 wh=self.r.createWhileLoop("w1")
150 n=self.r.createFuncNode("","w1.node3")
157 n.edAddOutputPort("p1",ti)
159 cport=wh.edGetConditionPort()
160 cport.edInitBool(True)
162 p.edAddLink(n.getOutputPort("p1"),wh.getInputPort("condition")) #or cport
164 # --- create a switch
165 sw=self.r.createSwitch("sw1")
167 n=self.r.createFuncNode("","sw1.node3")
174 n.edAddOutputPort("p1",ti)
176 n=self.r.createFuncNode("","sw1.node4")
183 n.edAddOutputPort("p1",ti)
184 sw.edSetDefaultNode(n)
185 sw.edGetConditionPort().edInitInt(1)
190 except pilot.Exception,ex:
194 #self.e.displayDot(p)
198 U = os.getenv('USER')
199 f=open("/tmp/" + U + "/UnitTestsResult", 'a')
200 f.write(" --- TEST src/yacsloader: testEdit.py\n")
201 suite = unittest.makeSuite(TestEdit)
202 unittest.TextTestRunner(f, descriptions=1, verbosity=1).run(suite)