Salome HOME
46f7ead4fa7867164954aa2c8a563f1b7b3e301e
[modules/yacs.git] / src / yacsloader / testCppPluginInvokation.py
1 #!/usr/bin/env python3
2 # Copyright (C) 2018-2020  CEA/DEN, EDF R&D
3 #
4 # This library is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU Lesser General Public
6 # License as published by the Free Software Foundation; either
7 # version 2.1 of the License, or (at your option) any later version.
8 #
9 # This library is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12 # Lesser General Public License for more details.
13 #
14 # You should have received a copy of the GNU Lesser General Public
15 # License along with this library; if not, write to the Free Software
16 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
17 #
18 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #
20
21 import unittest
22 import pilot
23 import SALOMERuntime
24 import loader
25
26
27 SALOMERuntime.RuntimeSALOME.setRuntime()
28 r=SALOMERuntime.getSALOMERuntime()
29
30 p=r.createProc("prTest1")
31 ti=p.createType("int","int")
32 tdi=p.createSequenceTc("seqint","seqint",ti)
33
34 node0=r.createScriptNode("Salome","Func0")
35 node0.setScript("""o1=[1,4,3,2,0,6,7,8]""")
36 out0=node0.edAddOutputPort("o1",tdi)
37 p.edAddChild(node0)
38 #
39 node1=r.createForEachLoop("ForEachLoop_pyobj1",ti)
40 p.edAddChild(node1)
41 p.edAddCFLink(node0,node1)
42 p.edAddLink(out0,node1.edGetSeqOfSamplesPort())
43 node1.edGetNbOfBranchesPort().edInitInt(2)
44 #
45 node2=r.createScriptNode("Salome","Func1")
46 node2.setScript("""o2=i1*i1""")
47 i1=node2.edAddInputPort("i1",ti)
48 o2=node2.edAddOutputPort("o2",ti)
49 node1.edAddChild(node2)
50 p.edAddLink(node1.edGetSamplePort(),i1)
51
52 p.saveSchema("thomas.xml")
53
54 ex=pilot.ExecutorSwig()
55 assert(p.getState()==pilot.READY)
56 pilot.LoadObserversPluginIfAny(p,ex)
57 ex.RunW(p,0)
58 assert(p.getState()==pilot.DONE)
59 pilot.UnLoadObserversPluginIfAny()
60
61
62 for i in range(100):
63     print(30*"*"+" %d"%i)
64     l=loader.YACSLoader()
65     p=l.load("thomas.xml")
66     ex=pilot.ExecutorSwig()
67     assert(p.getState()==pilot.READY)
68     pilot.LoadObserversPluginIfAny(p,ex)
69     ex.RunW(p,0)
70     assert(p.getState()==pilot.DONE)
71     pilot.UnLoadObserversPluginIfAny()
72