Salome HOME
Revert "Synchronize adm files"
[modules/yacs.git] / src / yacsloader_swig / Test / testEdit.py
1 # Copyright (C) 2006-2014  CEA/DEN, EDF R&D
2 #
3 # This library is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU Lesser General Public
5 # License as published by the Free Software Foundation; either
6 # version 2.1 of the License, or (at your option) any later version.
7 #
8 # This library is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 # Lesser General Public License for more details.
12 #
13 # You should have received a copy of the GNU Lesser General Public
14 # License along with this library; if not, write to the Free Software
15 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 #
17 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 #
19
20 import sys
21 import pilot
22 import SALOMERuntime
23 import loader
24 import unittest
25
26 class TestEdit(unittest.TestCase):
27
28     def setUp(self):
29         SALOMERuntime.RuntimeSALOME_setRuntime()
30         self.r = pilot.getRuntime()
31         self.l = loader.YACSLoader()
32         self.e = pilot.ExecutorSwig()
33         pass
34
35     def test1_edit(self):
36         p = self.r.createProc("pr")
37         print p.typeMap
38         t=p.getTypeCode("double")
39         print t.kind()
40         t=p.typeMap["double"]
41         
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()
53         print tc4.isA(tc1),0
54         print tc2.isA(tc1),1
55         print tc1.isA(tc2),0
56         print td.isA(ti),0
57         print td.isAdaptable(ti),1
58         print ti.isAdaptable(td),0
59         print tc5.isAdaptable(tc3),0
60         print tc3.isAdaptable(tc5),1
61         
62         n=self.r.createScriptNode("","node1")
63         n.setScript("print 'coucou1'")
64         n.edAddInputPort("p1",ti)
65         n.edAddOutputPort("p1",ti)
66         p.edAddChild(n)
67         inport=n.getInputPort("p1");
68         retex=None
69         try:
70             inport.edInitXML("<value><intt>5</int></value>")
71         except ValueError, ex:
72             print "Value Error: ", ex
73             retex=ex
74         except pilot.Exception,ex:
75             print "YACS exception:",ex.what()
76             retex=ex.what()
77         self.assert_(retex is not None, "exception not raised, or wrong type")
78         inport.edInitXML("<value><int>5</int></value>")
79
80         # --- create script node node2
81         n2=self.r.createScriptNode("","node2")
82         n2.setScript("print 'coucou2'")
83         n2.edAddInputPort("p1",ti)
84         p.edAddChild(n2)
85         # --- end of node
86
87         # --- control link between nodes n and n2
88         p.edAddCFLink(n,n2)
89         # --- end control link
90
91         # --- datalink between ports p1 of nodes n1 and n2
92         p.edAddLink(n.getOutputPort("p1"),n2.getInputPort("p1"))
93         # --- end datalink
94
95         n=self.r.createFuncNode("","node3")
96         n.setScript("""
97         def f():
98         print 'coucou3'
99         """)
100         n.setFname("f")
101         p.edAddChild(n)
102
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)
108         p.edAddChild(n4)
109         
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)
115         p.edAddChild(n5)
116
117         p.edAddLink(n4.getOutputDataStreamPort("pout"),n5.getInputDataStreamPort("pin"))
118
119         #n=self.r.createCompoNode("","node5")
120         #n.setRef("PYHELLO")
121         #n.setMethod("makeBanner")
122         #p.edAddChild(n)
123
124         # --- create a bloc with one node
125         b=self.r.createBloc("b1")
126         p.edAddChild(b)
127         
128         n=self.r.createScriptNode("","b1.node2")
129         n.setScript("print 'coucou2'")
130         b.edAddChild(n)
131         # --- end bloc
132
133         # --- create a for loop with one node
134         lo=self.r.createForLoop("l1")
135         p.edAddChild(lo)
136         ip=lo.edGetNbOfTimesInputPort()
137         ip.edInitInt(3)
138
139         n=self.r.createScriptNode("","l1.node2")
140         n.setScript("print 'coucou2'")
141         lo.edSetNode(n)
142         # --- end loop
143
144         # --- control link between bloc b1 and loop l1
145         p.edAddCFLink(b,lo)
146         # --- end control link
147
148         # --- create a while loop with one node
149         wh=self.r.createWhileLoop("w1")
150         p.edAddChild(wh)
151         n=self.r.createFuncNode("","w1.node3")
152         n.setScript("""
153 def f():
154   print 'coucou3'
155   return 0
156 """)
157         n.setFname("f")
158         n.edAddOutputPort("p1",ti)
159         wh.edSetNode(n)
160         cport=wh.edGetConditionPort()
161         cport.edInitBool(True)
162         # --- end loop
163         p.edAddLink(n.getOutputPort("p1"),wh.getInputPort("condition")) #or cport
164
165         # --- create a switch 
166         sw=self.r.createSwitch("sw1")
167         p.edAddChild(sw)
168         n=self.r.createFuncNode("","sw1.node3")
169         n.setScript("""
170 def f():
171   print 'case1'
172   return 0
173 """)
174         n.setFname("f")
175         n.edAddOutputPort("p1",ti)
176         sw.edSetNode(1,n)
177         n=self.r.createFuncNode("","sw1.node4")
178         n.setScript("""
179 def f():
180   print 'default'
181   return 0
182 """)
183         n.setFname("f")
184         n.edAddOutputPort("p1",ti)
185         sw.edSetDefaultNode(n)
186         sw.edGetConditionPort().edInitInt(1)
187         # --- end switch
188
189         try:
190           self.e.RunW(p,0)
191         except pilot.Exception,ex:
192           print ex.what()
193           self.fail(ex)
194         
195         #self.e.displayDot(p)
196
197
198 import os
199 U = os.getenv('USER')
200 f=open("/tmp/" + U + "/UnitTestsResult", 'a')
201 f.write("  --- TEST src/yacsloader: testEdit.py\n")
202 suite = unittest.makeSuite(TestEdit)
203 result=unittest.TextTestRunner(f, descriptions=1, verbosity=1).run(suite)
204 f.close()
205 sys.exit(not result.wasSuccessful())