Salome HOME
[ICoCo]: ICoCo part as a new sub library: libmedicoco.so
[tools/medcoupling.git] / src / ICoCo / Swig / ICoCoMEDFieldTest.py
1 #  -*- coding: iso-8859-1 -*-
2 # Copyright (C) 2007-2019  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 from medcoupling import *
22
23 import unittest
24
25 class ICoCoICoCoMEDDoubleFieldTest(unittest.TestCase):
26   def generate_fields_double(self):
27     """ Dummy MCFieldDouble """
28     msh = MEDCouplingCMesh("toto_mesh")
29     msh.setCoords(DataArrayDouble([0.,1.,2.]))
30     msh = msh.buildUnstructured()
31     f1 = MEDCouplingFieldDouble(ON_CELLS, ONE_TIME)
32     f1.setMesh(msh)
33     f1.setName("toto")
34     f1.setArray(DataArrayDouble([0.,1.,2.,3.]))
35
36     f2 = f1.deepCopy()
37     da = f2.getArray()
38     da += 3.5
39     da2 = f2.getArray()
40     return f1, f2
41
42   def generate_fields_int(self):
43     """ Dummy MCFieldDouble """
44     msh = MEDCouplingCMesh("toto_mesh")
45     msh.setCoords(DataArrayDouble([0.,1.,2.]))
46     msh = msh.buildUnstructured()
47     f1 = MEDCouplingFieldInt32(ON_CELLS, ONE_TIME)
48     f1.setMesh(msh)
49     f1.setName("toto")
50     f1.setArray(DataArrayInt32([0,1,2,3]))
51
52     f2 = f1.deepCopy()
53     da = f2.getArray()
54     da += 3
55     da2 = f2.getArray()
56     return f1, f2
57
58   def test1(self):
59     lst_typ = [ICoCoMEDDoubleField, ICoCoMEDIntField]
60     f1d, f2d = self.generate_fields_double()
61     f1i, f2i = self.generate_fields_int()
62     fld1_lst = [f1d, f1i]
63     fld2_lst = [f2d, f2i]
64     for ICoCoMED_T_Field, f1, f2 in zip(lst_typ, fld1_lst, fld2_lst):
65         mf = ICoCoMED_T_Field()
66         mf.setName("titi")
67         self.assertEqual(mf.getName(), "titi")
68         mfd = mf.getMCField()
69         self.assertTrue(mfd is None)
70         mf.setMCField(f1)
71         f11 = mf.getMCField()
72         self.assertEqual(f1.getHiddenCppPointer(), f11.getHiddenCppPointer())  # strictly the same
73         self.assertEqual(mf.getName(), "toto")   # name is taken from MC object
74         mf.setMCField(f2)
75         f22 = mf.getMCField()
76         self.assertEqual(f2.getHiddenCppPointer(), f22.getHiddenCppPointer())  # strictly the same
77
78         mf = ICoCoMED_T_Field(f1)   # ctor with MC object
79         mfd = mf.getMCField()
80         self.assertEqual(mfd.getHiddenCppPointer(), f1.getHiddenCppPointer())  # strictly the same
81         self.assertEqual(mf.getName(), "toto")   # name is taken from MC object
82
83         mf.setMCField(None)
84         mfd = mf.getMCField()
85         self.assertTrue(mfd is None)
86         self.assertEqual(mf.getName(), "")   # name is reset
87
88         mf.setMCField(f2)
89         f22 = mf.getMCField()
90         self.assertEqual(f2.getHiddenCppPointer(), f22.getHiddenCppPointer())  # strictly the same
91
92         mf.setName("aa")
93         mf2 = ICoCoMED_T_Field(mf)  # copy ctor
94         f22 = mf2.getMCField()
95         self.assertEqual(f2.getHiddenCppPointer(), f22.getHiddenCppPointer())  # strictly the same
96         self.assertEqual(mf2.getName(), "aa")
97
98         mf2 = mf  # assignement op
99         f22 = mf2.getMCField()
100         self.assertEqual(f2.getHiddenCppPointer(), f22.getHiddenCppPointer())  # strictly the same
101         self.assertEqual(mf2.getName(), "aa")
102
103         mf2.setMCField(None)
104         self.assertEqual(mf2.getName(), "")
105
106 if __name__ == '__main__':
107     unittest.main()