Salome HOME
Copyright update 2022
[tools/yacsgen.git] / Examples / hxx1 / test_compohxx.py
1 #==============================================================================
2 #  File      : CALCUL_test.py
3 #  Created   :
4 #  Author    :
5 #  Project   : SALOME
6 #  Copyright : CEA 2005-2022
7 #==============================================================================
8 #
9 # Test du composant CALCUL
10 #
11 import SALOME
12 import salome
13 salome.salome_init()
14 print("Test du composant CALCUL genere par hxx2salome")
15 import hxxcompos_ORB
16 myCalc = salome.lcc.FindOrLoadComponent("FactoryServer", "CALCUL")
17 print("10+15 = ",myCalc.add(10,15))
18 print("10x15 = ",myCalc.mul(10,15))
19 #print "6!    = ",myCalc.fact(6)
20 res1,res2 = myCalc.sqr2(12.0)
21 print("12*12 = ",res1," ",res2)
22 j=1
23 i1,i2,i3 = myCalc.return_3_int(j)
24 assert (i1 == j+1),'Erreur dans la fonction return_3_int'
25 assert (i2 == j+2),'Erreur dans la fonction return_3_int'
26 assert (i3 == j+3),'Erreur dans la fonction return_3_int'
27 print('return_3_int : ',j,' ',i1,' ',i2,' ',i3)
28 print("True && True  = ",myCalc.And(True,True))
29 print("True && False = ",myCalc.And(True,False))
30 print("True || False = ",myCalc.Or(True,False))
31 from math import fabs
32 assert (fabs(res1-144.0)<1.0e-6 ), 'Erreur dans la fonction myCalc.sqr2 : 12*12 = '+str(res1)
33 assert ( myCalc.And(True,True)==True ) , 'Erreur dans la fonction And(True,True)'
34 assert ( myCalc.And(True,False)==False ) , 'Erreur dans la fonction And(True,False)'
35 assert ( myCalc.Or(True,False)==True ) , 'Erreur dans la fonction Or(True,False)'
36 print("Fin test hxx2salome/001/A1")
37 #
38 myCoco = salome.lcc.FindOrLoadComponent("FactoryServerI", "ICOCO")
39 #
40 liste_champs = myCoco.getInputFieldsNames()
41 nb_champs=len(liste_champs)
42 print("Nombre de champs = ",nb_champs)
43 assert  nb_champs == 2 , 'erreur dans le nombre de champs, different de 2!'
44 #
45 print("Champ 1 (SourceField) : ",liste_champs[0])
46 print("Champ 2 (TargetField) : ",liste_champs[1])
47 assert liste_champs[0] == "SourceField", 'erreur dans le nom du champ 1'
48 assert liste_champs[1] == "TargetField", 'erreur dans le nom du champ 2'
49 #
50 print("Fin test hxx2salome/ICOCO/A1")
51 myCoco1 = salome.lcc.FindOrLoadComponent("FactoryServerI1", "ICOCO")
52 myCoco2 = salome.lcc.FindOrLoadComponent("FactoryServerI2", "ICOCO")
53 #
54 myCoco1.initialize()
55 m=myCoco1.getInputFieldTemplate("TargetField")
56 myCoco1.solve()  #to test with 5.1.5
57 f=myCoco1.getOutputField("SourceField")
58 myCoco2.printField(f)
59 #
60 print("##################################")
61 print("Fin test hxx2salome/ICOCO/A2")