1 #cython: autotestdict=True
3 # -------------------------------------------------------------------
5 cdef extern from "ctypedef_int_types_chdr_T333.h":
6 ctypedef int SChar ## "signed char"
7 ctypedef int UChar ## "unsigned char"
8 ctypedef int SShort ## "signed short"
9 ctypedef int UShort ## "unsigned short"
10 ctypedef int SInt ## "signed int"
11 ctypedef int UInt ## "unsigned int"
12 ctypedef int SLong ## "signed long"
13 ctypedef int ULong ## "unsigned long"
14 ctypedef int SLongLong ## "signed PY_LONG_LONG"
15 ctypedef int ULongLong ## "unsigned PY_LONG_LONG"
17 # -------------------------------------------------------------------
19 SCHAR_MAX = <SChar>((<UChar>-1)>>1)
20 SCHAR_MIN = (-SCHAR_MAX-1)
22 def test_schar(SChar x):
24 >>> test_schar(-129) #doctest: +ELLIPSIS
25 Traceback (most recent call last):
34 >>> test_schar(128) #doctest: +ELLIPSIS
35 Traceback (most recent call last):
41 def test_add_schar(x, y):
43 >>> test_add_schar(SCHAR_MIN, -1) #doctest: +ELLIPSIS
44 Traceback (most recent call last):
47 >>> test_add_schar(SCHAR_MIN, 0) == SCHAR_MIN
49 >>> test_add_schar(SCHAR_MIN, 1) == SCHAR_MIN+1
51 >>> test_add_schar(SCHAR_MAX, -1) == SCHAR_MAX-1
53 >>> test_add_schar(SCHAR_MAX, 0) == SCHAR_MAX
55 >>> test_add_schar(SCHAR_MAX, 1) #doctest: +ELLIPSIS
56 Traceback (most recent call last):
63 UCHAR_MAX = <UChar>((<UChar>-1))
65 def test_uchar(UChar x):
67 >>> test_uchar(-1) #doctest: +ELLIPSIS
68 Traceback (most recent call last):
75 >>> test_uchar(UCHAR_MAX) == UCHAR_MAX
77 >>> test_uchar(UCHAR_MAX+1) #doctest: +ELLIPSIS
78 Traceback (most recent call last):
84 def test_add_uchar(x, y):
86 >>> test_add_uchar(UCHAR_MAX, 0) == UCHAR_MAX
88 >>> test_add_uchar(UCHAR_MAX, 1) #doctest: +ELLIPSIS
89 Traceback (most recent call last):
96 # -------------------------------------------------------------------
98 SSHORT_MAX = <SShort>((<UShort>-1)>>1)
99 SSHORT_MIN = (-SSHORT_MAX-1)
101 def test_sshort(short x):
103 >>> test_sshort(SSHORT_MIN-1) #doctest: +ELLIPSIS
104 Traceback (most recent call last):
107 >>> test_sshort(SSHORT_MIN) == SSHORT_MIN
115 >>> test_sshort(SSHORT_MAX) == SSHORT_MAX
117 >>> test_sshort(SSHORT_MAX+1) #doctest: +ELLIPSIS
118 Traceback (most recent call last):
124 def test_add_sshort(x, y):
126 >>> test_add_sshort(SSHORT_MIN, -1) #doctest: +ELLIPSIS
127 Traceback (most recent call last):
130 >>> test_add_sshort(SSHORT_MIN, 0) == SSHORT_MIN
132 >>> test_add_sshort(SSHORT_MIN, 1) == SSHORT_MIN+1
134 >>> test_add_sshort(SSHORT_MAX, -1) == SSHORT_MAX-1
136 >>> test_add_sshort(SSHORT_MAX, 0) == SSHORT_MAX
138 >>> test_add_sshort(SSHORT_MAX, 1) #doctest: +ELLIPSIS
139 Traceback (most recent call last):
143 cdef SShort r = x + y
146 USHORT_MAX = <UShort>((<UShort>-1))
148 def test_ushort(UShort x):
150 >>> test_ushort(-1) #doctest: +ELLIPSIS
151 Traceback (most recent call last):
158 >>> test_ushort(USHORT_MAX) == USHORT_MAX
160 >>> test_ushort(USHORT_MAX+1) #doctest: +ELLIPSIS
161 Traceback (most recent call last):
167 def test_add_ushort(x, y):
169 >>> test_add_ushort(USHORT_MAX, 0) == USHORT_MAX
171 >>> test_add_ushort(USHORT_MAX, 1) #doctest: +ELLIPSIS
172 Traceback (most recent call last):
176 cdef UShort r = x + y
179 # -------------------------------------------------------------------
181 SINT_MAX = <SInt>((<UInt>-1)>>1)
182 SINT_MIN = (-SINT_MAX-1)
184 def test_sint(int x):
186 >>> test_sint(SINT_MIN-1) #doctest: +ELLIPSIS
187 Traceback (most recent call last):
190 >>> test_sint(SINT_MIN) == SINT_MIN
198 >>> test_sint(SINT_MAX) == SINT_MAX
200 >>> test_sint(SINT_MAX+1) #doctest: +ELLIPSIS
201 Traceback (most recent call last):
207 def test_add_sint(x, y):
209 >>> test_add_sint(SINT_MIN, -1) #doctest: +ELLIPSIS
210 Traceback (most recent call last):
213 >>> test_add_sint(SINT_MIN, 0) == SINT_MIN
215 >>> test_add_sint(SINT_MIN, 1) == SINT_MIN+1
217 >>> test_add_sint(SINT_MAX, -1) == SINT_MAX-1
219 >>> test_add_sint(SINT_MAX, 0) == SINT_MAX
221 >>> test_add_sint(SINT_MAX, 1) #doctest: +ELLIPSIS
222 Traceback (most recent call last):
229 UINT_MAX = <UInt>(<UInt>-1)
231 def test_uint(UInt x):
233 >>> test_uint(-1) #doctest: +ELLIPSIS
234 Traceback (most recent call last):
237 >>> print(test_uint(0))
239 >>> print(test_uint(1))
241 >>> test_uint(UINT_MAX) == UINT_MAX
243 >>> test_uint(UINT_MAX+1) #doctest: +ELLIPSIS
244 Traceback (most recent call last):
250 def test_add_uint(x, y):
252 >>> test_add_uint(UINT_MAX, 0) == UINT_MAX
254 >>> test_add_uint(UINT_MAX, 1) #doctest: +ELLIPSIS
255 Traceback (most recent call last):
262 # -------------------------------------------------------------------
264 SLONG_MAX = <SLong>((<ULong>-1)>>1)
265 SLONG_MIN = (-SLONG_MAX-1)
267 def test_slong(long x):
269 >>> test_slong(SLONG_MIN-1) #doctest: +ELLIPSIS
270 Traceback (most recent call last):
273 >>> test_slong(SLONG_MIN) == SLONG_MIN
281 >>> test_slong(SLONG_MAX) == SLONG_MAX
283 >>> test_slong(SLONG_MAX+1) #doctest: +ELLIPSIS
284 Traceback (most recent call last):
290 def test_add_slong(x, y):
292 >>> test_add_slong(SLONG_MIN, -1) #doctest: +ELLIPSIS
293 Traceback (most recent call last):
296 >>> test_add_slong(SLONG_MIN, 0) == SLONG_MIN
298 >>> test_add_slong(SLONG_MIN, 1) == SLONG_MIN+1
300 >>> test_add_slong(SLONG_MAX, -1) == SLONG_MAX-1
302 >>> test_add_slong(SLONG_MAX, 0) == SLONG_MAX
304 >>> test_add_slong(SLONG_MAX, 1) #doctest: +ELLIPSIS
305 Traceback (most recent call last):
312 ULONG_MAX = <ULong>(<ULong>-1)
314 def test_ulong(ULong x):
316 >>> test_ulong(-1) #doctest: +ELLIPSIS
317 Traceback (most recent call last):
320 >>> print(test_ulong(0))
322 >>> print(test_ulong(1))
324 >>> test_ulong(ULONG_MAX) == ULONG_MAX
326 >>> test_ulong(ULONG_MAX+1) #doctest: +ELLIPSIS
327 Traceback (most recent call last):
333 def test_add_ulong(x, y):
335 >>> test_add_ulong(ULONG_MAX, 0) == ULONG_MAX
337 >>> test_add_ulong(ULONG_MAX, 1) #doctest: +ELLIPSIS
338 Traceback (most recent call last):
345 # -------------------------------------------------------------------
347 SLONGLONG_MAX = <SLongLong>((<ULongLong>-1)>>1)
348 SLONGLONG_MIN = (-SLONGLONG_MAX-1)
350 def test_slonglong(long long x):
352 >>> test_slonglong(SLONGLONG_MIN-1) #doctest: +ELLIPSIS
353 Traceback (most recent call last):
356 >>> test_slonglong(SLONGLONG_MIN) == SLONGLONG_MIN
358 >>> print(test_slonglong(-1))
360 >>> print(test_slonglong(0))
362 >>> print(test_slonglong(1))
364 >>> test_slonglong(SLONGLONG_MAX) == SLONGLONG_MAX
366 >>> test_slonglong(SLONGLONG_MAX+1) #doctest: +ELLIPSIS
367 Traceback (most recent call last):
373 def test_add_slonglong(x, y):
375 >>> test_add_slonglong(SLONGLONG_MIN, -1) #doctest: +ELLIPSIS
376 Traceback (most recent call last):
379 >>> test_add_slonglong(SLONGLONG_MIN, 0) == SLONGLONG_MIN
381 >>> test_add_slonglong(SLONGLONG_MIN, 1) == SLONGLONG_MIN+1
383 >>> test_add_slonglong(SLONGLONG_MAX, -1) == SLONGLONG_MAX-1
385 >>> test_add_slonglong(SLONGLONG_MAX, 0) == SLONGLONG_MAX
387 >>> test_add_slonglong(SLONGLONG_MAX, 1) #doctest: +ELLIPSIS
388 Traceback (most recent call last):
392 cdef SLongLong r = x + y
395 ULONGLONG_MAX = <ULongLong>(<ULongLong>-1)
397 def test_ulonglong(ULongLong x):
399 >>> test_ulonglong(-1) #doctest: +ELLIPSIS
400 Traceback (most recent call last):
403 >>> print(test_ulonglong(0))
405 >>> print(test_ulonglong(1))
407 >>> test_ulonglong(ULONGLONG_MAX) == ULONGLONG_MAX
409 >>> test_ulonglong(ULONGLONG_MAX+1) #doctest: +ELLIPSIS
410 Traceback (most recent call last):
416 def test_add_ulonglong(x, y):
418 >>> test_add_ulonglong(ULONGLONG_MAX, 0) == ULONGLONG_MAX
420 >>> test_add_ulonglong(ULONGLONG_MAX, 1) #doctest: +ELLIPSIS
421 Traceback (most recent call last):
425 cdef ULongLong r = x + y
428 # -------------------------------------------------------------------
434 >>> vals = (SCHAR_MIN, UCHAR_MAX,
435 ... SSHORT_MIN, USHORT_MAX,
436 ... SINT_MIN, UINT_MAX,
437 ... SLONG_MIN, ULONG_MAX,
438 ... SLONGLONG_MIN, ULONGLONG_MAX)
439 >>> a.setvalues(*vals)
440 >>> a.getvalues() == vals
443 >>> vals = (SCHAR_MAX, UCHAR_MAX,
444 ... SSHORT_MAX, USHORT_MAX,
445 ... SINT_MAX, UINT_MAX,
446 ... SLONG_MAX, ULONG_MAX,
447 ... SLONGLONG_MAX, ULONGLONG_MAX)
448 >>> a.setvalues(*vals)
449 >>> a.getvalues() == vals
453 >>> a.setvalues(*vals)
454 >>> a.getvalues() == vals
468 SLongLong attr_slonglong
469 ULongLong attr_ulonglong
471 cpdef setvalues(self,
480 SLongLong arg_slonglong ,
481 ULongLong arg_ulonglong ):
482 self.attr_schar = arg_schar
483 self.attr_uchar = arg_uchar
484 self.attr_sshort = arg_sshort
485 self.attr_ushort = arg_ushort
486 self.attr_sint = arg_sint
487 self.attr_uint = arg_uint
488 self.attr_slong = arg_slong
489 self.attr_ulong = arg_ulong
490 self.attr_slonglong = arg_slonglong
491 self.attr_ulonglong = arg_ulonglong
493 cpdef getvalues(self):
494 return (self.attr_schar ,
502 self.attr_slonglong ,
503 self.attr_ulonglong )
506 # -------------------------------------------------------------------
509 ctypedef signed MySInt1 "signed short"
510 ctypedef unsigned MyUInt1 "unsigned short"
512 def test_MySInt1(MySInt1 x):
523 def test_MyUInt1(MyUInt1 x):
525 >>> test_MyUInt1(-1) #doctest: +ELLIPSIS
526 Traceback (most recent call last):
537 ctypedef signed MySInt2 "signed short"
538 ctypedef unsigned MyUInt2 "unsigned short"
540 def test_MySInt2(MySInt2 x):
551 def test_MyUInt2(MyUInt2 x):
553 >>> test_MyUInt2(-1) #doctest: +ELLIPSIS
554 Traceback (most recent call last):
564 # -------------------------------------------------------------------
566 cimport ctypedef_int_types_defs_T333 as defs
568 def test_DefSInt(defs.SInt x):
579 def test_DefUChar(defs.UChar x):
581 >>> test_DefUChar(-1) #doctest: +ELLIPSIS
582 Traceback (most recent call last):
592 def test_ExtSInt(defs.ExtSInt x):
603 def test_ExtUInt(defs.ExtUInt x):
605 >>> test_ExtUInt(-1) #doctest: +ELLIPSIS
606 Traceback (most recent call last):
617 ctypedef defs.SShort LocSInt
618 ctypedef defs.UShort LocUInt
620 def test_LocSInt(LocSInt x):
631 def test_LocUInt(LocUInt x):
633 >>> test_LocUInt(-1) #doctest: +ELLIPSIS
634 Traceback (most recent call last):
644 # -------------------------------------------------------------------