1 # -*- coding: iso-8859-1 -*-
2 # Copyright (C) 2007-2014 CEA/DEN, EDF R&D, OPEN CASCADE
4 # Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
5 # CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
7 # This library is free software; you can redistribute it and/or
8 # modify it under the terms of the GNU Lesser General Public
9 # License as published by the Free Software Foundation; either
10 # version 2.1 of the License, or (at your option) any later version.
12 # This library is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 # Lesser General Public License for more details.
17 # You should have received a copy of the GNU Lesser General Public
18 # License along with this library; if not, write to the Free Software
19 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
25 __date__ ="$17 avr. 2010 19:44:36$"
27 from enumerate import Enumerate
28 from datamodeler import DataModeler, TypeString, TypeInteger
29 from salome.kernel import Callable
31 class TestData(DataModeler):
33 This class is the placeholder for meta data associated to a study case.
34 The meta-data are used for organisation and indexing purposes
36 TYPES_LIST=Enumerate([
42 DataModeler.__init__(self)
51 range = self.TYPES_LIST.listvalues()
54 def setName(self, value):
60 def setType(self, value):
68 Create a default instance of TestData
72 testdata.NAME = "my case"
73 testdata.TYPE = TestData.TYPES_LIST.SEP
76 getDefault = Callable(getDefault)
78 # ==============================================================================
79 # Basic use cases and unit tests
80 # ==============================================================================
82 from uiexception import UiException
86 testdata.setName("Sous-epaisseur")
87 testdata.setType(TestData.TYPES_LIST.SEP)
88 if ( testdata.NAME != "Sous-epaisseur" ):
96 testdata.unknown = "unknown"
97 # This should not arrive here
99 except UiException, err:
103 def TEST_useBadType():
104 testdata = TestData()
106 testdata.TYPE = "unknown"
107 # This should not arrive here
109 except UiException, err:
113 def TEST_useBadRange():
114 testdata = TestData()
117 testdata.TYPE = TestData.TYPES_LIST.SEP
118 testdata.setType(TestData.TYPES_LIST.SEP)
119 # This should arrive here
120 except UiException, err:
126 testdata.TYPE = 9999 # a type that does not exist in the range
127 # This should not arrive here
129 except UiException, err:
133 def TEST_serialize():
135 ref_testdata = TestData()
136 ref_testdata.setName("The firts name")
137 res_testdata = salome.kernel.unserialize(salome.kernel.serialize(ref_testdata))
139 print res_testdata.getName()
141 if res_testdata.getName() != ref_testdata.getName():
144 # Is the unserialized data still functional?
146 res_testdata.setName("An other name")
147 print res_testdata.getName()
153 if __name__ == "__main__":
154 from unittester import run
155 run("salome/kernel/testdata","TEST_getName")
156 run("salome/kernel/testdata","TEST_useBadKey")
157 run("salome/kernel/testdata","TEST_useBadType")
158 run("salome/kernel/testdata","TEST_useBadRange")
159 run("salome/kernel/testdata","TEST_serialize")