PageRenderTime 38ms CodeModel.GetById 15ms app.highlight 20ms RepoModel.GetById 1ms app.codeStats 0ms

/trunk/Examples/test-suite/python/primitive_types_runme.py

#
Python | 342 lines | 309 code | 28 blank | 5 comment | 27 complexity | d385811f59bc39a0294dfaeb4551d93d MD5 | raw file
  1from primitive_types import *
  2
  3var_init()
  4
  5# assigning globals calls
  6cvar.var_bool = sct_bool
  7cvar.var_schar = sct_schar
  8cvar.var_uchar = sct_uchar
  9cvar.var_int = sct_int
 10cvar.var_uint = sct_uint
 11cvar.var_short = sct_short
 12cvar.var_ushort = sct_ushort
 13cvar.var_long = sct_long
 14cvar.var_ulong = sct_ulong
 15cvar.var_llong = sct_llong
 16cvar.var_ullong = sct_ullong
 17cvar.var_char = sct_char
 18cvar.var_pchar = sct_pchar
 19cvar.var_pcharc = sct_pcharc
 20cvar.var_pint = sct_pint
 21cvar.var_sizet = sct_sizet
 22cvar.var_hello = sct_hello
 23cvar.var_myint = sct_myint
 24cvar.var_namet = def_namet
 25cvar.var_parami = sct_parami
 26cvar.var_paramd = sct_paramd
 27cvar.var_paramc = sct_paramc
 28
 29v_check()
 30
 31def pyerror(name, val, cte):
 32  print "bad val/cte", name, val, cte
 33  raise RuntimeError
 34  pass
 35
 36if cvar.var_bool != cct_bool: pyerror("bool", cvar.var_bool, cct_bool)
 37if cvar.var_schar != cct_schar: pyerror("schar", cvar.var_schar, cct_schar)
 38if cvar.var_uchar != cct_uchar: pyerror("uchar", cvar.var_uchar, cct_uchar)
 39if cvar.var_int != cct_int: pyerror("int", cvar.var_int, cct_int)
 40if cvar.var_uint != cct_uint: pyerror("uint", cvar.var_uint, cct_uint)
 41if cvar.var_short != cct_short: pyerror("short", cvar.var_short, cct_short)
 42if cvar.var_ushort != cct_ushort: pyerror("ushort", cvar.var_ushort, cct_ushort)
 43if cvar.var_long != cct_long: pyerror("long", cvar.var_long, cct_long)
 44if cvar.var_ulong != cct_ulong: pyerror("ulong", cvar.var_ulong, cct_ulong)
 45if cvar.var_llong != cct_llong: pyerror("llong", cvar.var_llong, cct_llong)
 46if cvar.var_ullong != cct_ullong: pyerror("ullong", cvar.var_ullong, cct_ullong)
 47if cvar.var_char != cct_char: pyerror("char", cvar.var_char, cct_char)
 48if cvar.var_pchar != cct_pchar: pyerror("pchar", cvar.var_pchar, cct_pchar)
 49if cvar.var_pcharc != cct_pcharc: pyerror("pchar", cvar.var_pcharc, cct_pcharc)
 50if cvar.var_pint != cct_pint: pyerror("pint", cvar.var_pint, cct_pint)
 51if cvar.var_sizet != cct_sizet: pyerror("sizet", cvar.var_sizet, cct_sizet)
 52if cvar.var_hello != cct_hello: pyerror("hello", cvar.var_hello, cct_hello)
 53if cvar.var_myint != cct_myint: pyerror("myint", cvar.var_myint, cct_myint)
 54if cvar.var_namet != def_namet: pyerror("name", cvar.var_namet, def_namet)
 55
 56class PyTest (TestDirector):
 57  def __init__(self):
 58    TestDirector.__init__(self)
 59    pass
 60  def ident(self, x):
 61    return x
 62  
 63  def vval_bool(self, x): return self.ident(x)
 64  def vval_schar(self, x): return self.ident(x)
 65  def vval_uchar(self, x): return self.ident(x)
 66  def vval_int(self, x): return self.ident(x)
 67  def vval_uint(self, x): return self.ident(x)
 68  def vval_short(self, x): return self.ident(x)
 69  def vval_ushort(self, x): return self.ident(x)
 70  def vval_long(self, x): return self.ident(x)
 71  def vval_ulong(self, x): return self.ident(x)
 72  def vval_llong(self, x): return self.ident(x)
 73  def vval_ullong(self, x): return self.ident(x)
 74  def vval_float(self, x): return self.ident(x)
 75  def vval_double(self, x): return self.ident(x)
 76  def vval_char(self, x): return self.ident(x)
 77  def vval_pchar(self, x): return self.ident(x)
 78  def vval_pcharc(self, x): return self.ident(x)
 79  def vval_pint(self, x): return self.ident(x)
 80  def vval_sizet(self, x): return self.ident(x)
 81  def vval_hello(self, x): return self.ident(x)
 82  def vval_myint(self, x): return self.ident(x)
 83
 84  def vref_bool(self, x): return self.ident(x)
 85  def vref_schar(self, x): return self.ident(x)
 86  def vref_uchar(self, x): return self.ident(x)
 87  def vref_int(self, x): return self.ident(x)
 88  def vref_uint(self, x): return self.ident(x)
 89  def vref_short(self, x): return self.ident(x)
 90  def vref_ushort(self, x): return self.ident(x)
 91  def vref_long(self, x): return self.ident(x)
 92  def vref_ulong(self, x): return self.ident(x)
 93  def vref_llong(self, x): return self.ident(x)
 94  def vref_ullong(self, x): return self.ident(x)
 95  def vref_float(self, x): return self.ident(x)
 96  def vref_double(self, x): return self.ident(x)
 97  def vref_char(self, x): return self.ident(x)
 98  def vref_pchar(self, x): return self.ident(x)
 99  def vref_pcharc(self, x): return self.ident(x)
100  def vref_pint(self, x): return self.ident(x)
101  def vref_sizet(self, x): return self.ident(x)
102  def vref_hello(self, x): return self.ident(x)
103  def vref_myint(self, x): return self.ident(x)
104
105  pass
106
107
108t = Test()
109p = PyTest()
110
111
112# internal call check
113if t.c_check() != p.c_check():
114  raise RuntimeError, "bad director"
115
116p.var_bool = p.stc_bool
117p.var_schar = p.stc_schar
118p.var_uchar = p.stc_uchar
119p.var_int = p.stc_int
120p.var_uint = p.stc_uint
121p.var_short = p.stc_short
122p.var_ushort = p.stc_ushort
123p.var_long = p.stc_long
124p.var_ulong = p.stc_ulong
125p.var_llong = p.stc_llong
126p.var_ullong = p.stc_ullong
127p.var_char = p.stc_char
128p.var_pchar = sct_pchar
129p.var_pcharc = sct_pcharc
130p.var_pint = sct_pint
131p.var_sizet = sct_sizet
132p.var_hello = sct_hello
133p.var_myint = sct_myint
134p.var_namet = def_namet
135p.var_parami = sct_parami
136p.var_paramd = sct_paramd
137p.var_paramc = sct_paramc
138
139p.v_check()
140
141
142t.var_bool = t.stc_bool
143t.var_schar = t.stc_schar
144t.var_uchar = t.stc_uchar
145t.var_int = t.stc_int
146t.var_uint = t.stc_uint
147t.var_short = t.stc_short
148t.var_ushort = t.stc_ushort
149t.var_long = t.stc_long
150t.var_ulong = t.stc_ulong
151t.var_llong = t.stc_llong
152t.var_ullong = t.stc_ullong
153t.var_char = t.stc_char
154t.var_pchar = sct_pchar
155t.var_pcharc = sct_pcharc
156t.var_pint = sct_pint
157t.var_sizet = sct_sizet
158t.var_hello = sct_hello
159t.var_myint = sct_myint
160t.var_namet = def_namet
161t.var_parami = sct_parami
162t.var_paramd = sct_paramd
163t.var_paramc = sct_paramc
164
165t.v_check()
166
167# this value contains a '0' char!
168if def_namet != 'ho\0la':
169  print "bad namet", def_namet
170  raise RuntimeError
171
172t.var_namet = def_namet
173if t.var_namet != def_namet:
174  print "bad namet", t.var_namet, def_namet
175  raise RuntimeError
176
177t.var_namet = 'holac'
178
179if t.var_namet != 'holac':
180  print "bad namet", t.var_namet
181  raise RuntimeError
182
183t.var_namet = 'hol'
184
185if t.var_namet != 'hol':
186#if t.var_namet != 'hol\0\0':
187  print "bad namet", t.var_namet
188  raise RuntimeError
189
190
191cvar.var_char = '\0'
192if cvar.var_char != '\0':
193  raise RuntimeError, "bad char '0' case"
194  
195cvar.var_char = 0
196if cvar.var_char != '\0':
197  raise RuntimeError, "bad char '0' case"
198
199cvar.var_namet = '\0'
200#if cvar.var_namet != '\0\0\0\0\0':
201if cvar.var_namet != '':
202  print 'hola', '', cvar.var_namet
203  raise RuntimeError, "bad char '\0' case"
204
205cvar.var_namet = ''
206#if cvar.var_namet != '\0\0\0\0\0':
207if cvar.var_namet != '':
208  raise RuntimeError, "bad char empty case"
209
210cvar.var_pchar = None
211if cvar.var_pchar != None:
212  raise RuntimeError, "bad None case"
213
214cvar.var_pchar = ''
215if cvar.var_pchar != '':
216  print '%c' % (cvar.var_pchar[0],)
217  raise RuntimeError, "bad char empty case"
218
219cvar.var_pcharc = None
220if cvar.var_pcharc != None:
221  raise RuntimeError, "bad None case"
222
223cvar.var_pcharc = ''
224if cvar.var_pcharc != '':
225  raise RuntimeError, "bad char empty case"
226
227
228#
229# creating a raw char*
230#
231pc = new_pchar(5)
232pchar_setitem(pc, 0, 'h')
233pchar_setitem(pc, 1, 'o')
234pchar_setitem(pc, 2, 'l')
235pchar_setitem(pc, 3, 'a')
236pchar_setitem(pc, 4, 0)
237
238
239cvar.var_pchar = pc
240if cvar.var_pchar != "hola":
241  print cvar.var_pchar
242  raise RuntimeError, "bad pointer case"
243
244cvar.var_namet = pc
245#if cvar.var_namet != "hola\0":
246if cvar.var_namet != "hola":
247  raise RuntimeError, "bad pointer case"
248
249delete_pchar(pc)
250
251#
252# Now when things should fail
253#
254
255
256try:
257  error = 0
258  a = t.var_uchar
259  t.var_uchar = 10000
260  error = 1
261except OverflowError:
262  if a != t.var_uchar:
263    error = 1
264  pass
265if error:
266  raise RuntimeError, "bad uchar typemap"
267
268
269
270try:
271  error = 0
272  a = t.var_char
273  t.var_char = '23'
274  error = 1
275except TypeError:
276  if a != t.var_char:
277    error = 1
278  pass 
279if error:
280  raise RuntimeError, "bad char typemap"
281
282try:
283  error = 0
284  a = t.var_uint
285  t.var_uint = -1
286  error = 1
287except OverflowError:
288  if a != t.var_uint:
289    error = 1
290  pass 
291if error:
292  raise RuntimeError, "bad uint typemap"
293
294#
295#
296try:
297  error = 0
298  a = t.var_namet
299  t.var_namet = '123456'
300  error = 1
301except TypeError:
302  if a != t.var_namet:
303    error = 1
304  pass 
305if error:
306  raise RuntimeError, "bad namet typemap"
307
308#
309#
310#
311t2 = p.vtest(t)
312if t.var_namet !=  t2.var_namet:
313  raise RuntimeError, "bad SWIGTYPE* typemap"
314  
315
316if cvar.fixsize != 'ho\0la\0\0\0':
317  raise RuntimeError, "bad FIXSIZE typemap"
318
319cvar.fixsize = 'ho'
320if cvar.fixsize != 'ho\0\0\0\0\0\0':
321  raise RuntimeError, "bad FIXSIZE typemap"
322
323
324f = Foo(3)
325f1 = fptr_val(f)
326f2 = fptr_ref(f)
327if f1._a != f2._a:
328  raise RuntimeError, "bad const ptr& typemap"
329  
330
331v = char_foo(1,3)
332if v !=3:
333  raise RuntimeError, "bad int typemap"
334
335s = char_foo(1,"hello")
336if s !="hello":
337  raise RuntimeError, "bad char* typemap"
338  
339
340v = SetPos(1,3)
341if v !=4:
342  raise RuntimeError, "bad int typemap"