2 #cython: autotestdict=True
4 # -------------------------------------------------------------------
6 cdef extern from "ctypedef_int_types_chdr_T333.h":
7 ctypedef int SChar ## "signed char"
8 ctypedef int UChar ## "unsigned char"
9 ctypedef int SShort ## "signed short"
10 ctypedef int UShort ## "unsigned short"
11 ctypedef int SInt ## "signed int"
12 ctypedef int UInt ## "unsigned int"
13 ctypedef int SLong ## "signed long"
14 ctypedef int ULong ## "unsigned long"
15 ctypedef int SLongLong ## "signed PY_LONG_LONG"
16 ctypedef int ULongLong ## "unsigned PY_LONG_LONG"
18 # -------------------------------------------------------------------
20 SCHAR_MAX = <SChar>((<UChar>-1)>>1)
21 SCHAR_MIN = (-SCHAR_MAX-1)
23 def test_schar(SChar x):
25 >>> test_schar(-129) #doctest: +ELLIPSIS
26 Traceback (most recent call last):
35 >>> test_schar(128) #doctest: +ELLIPSIS
36 Traceback (most recent call last):
42 def test_add_schar(x, y):
44 >>> test_add_schar(SCHAR_MIN, -1) #doctest: +ELLIPSIS
45 Traceback (most recent call last):
48 >>> test_add_schar(SCHAR_MIN, 0) == SCHAR_MIN
50 >>> test_add_schar(SCHAR_MIN, 1) == SCHAR_MIN+1
52 >>> test_add_schar(SCHAR_MAX, -1) == SCHAR_MAX-1
54 >>> test_add_schar(SCHAR_MAX, 0) == SCHAR_MAX
56 >>> test_add_schar(SCHAR_MAX, 1) #doctest: +ELLIPSIS
57 Traceback (most recent call last):
64 UCHAR_MAX = <UChar>((<UChar>-1))
66 def test_uchar(UChar x):
68 >>> test_uchar(-1) #doctest: +ELLIPSIS
69 Traceback (most recent call last):
76 >>> test_uchar(UCHAR_MAX) == UCHAR_MAX
78 >>> test_uchar(UCHAR_MAX+1) #doctest: +ELLIPSIS
79 Traceback (most recent call last):
85 def test_add_uchar(x, y):
87 >>> test_add_uchar(UCHAR_MAX, 0) == UCHAR_MAX
89 >>> test_add_uchar(UCHAR_MAX, 1) #doctest: +ELLIPSIS
90 Traceback (most recent call last):
97 # -------------------------------------------------------------------
99 SSHORT_MAX = <SShort>((<UShort>-1)>>1)
100 SSHORT_MIN = (-SSHORT_MAX-1)
102 def test_sshort(short x):
104 >>> test_sshort(SSHORT_MIN-1) #doctest: +ELLIPSIS
105 Traceback (most recent call last):
108 >>> test_sshort(SSHORT_MIN) == SSHORT_MIN
116 >>> test_sshort(SSHORT_MAX) == SSHORT_MAX
118 >>> test_sshort(SSHORT_MAX+1) #doctest: +ELLIPSIS
119 Traceback (most recent call last):
125 def test_add_sshort(x, y):
127 >>> test_add_sshort(SSHORT_MIN, -1) #doctest: +ELLIPSIS
128 Traceback (most recent call last):
131 >>> test_add_sshort(SSHORT_MIN, 0) == SSHORT_MIN
133 >>> test_add_sshort(SSHORT_MIN, 1) == SSHORT_MIN+1
135 >>> test_add_sshort(SSHORT_MAX, -1) == SSHORT_MAX-1
137 >>> test_add_sshort(SSHORT_MAX, 0) == SSHORT_MAX
139 >>> test_add_sshort(SSHORT_MAX, 1) #doctest: +ELLIPSIS
140 Traceback (most recent call last):
144 cdef SShort r = x + y
147 USHORT_MAX = <UShort>((<UShort>-1))
149 def test_ushort(UShort x):
151 >>> test_ushort(-1) #doctest: +ELLIPSIS
152 Traceback (most recent call last):
159 >>> test_ushort(USHORT_MAX) == USHORT_MAX
161 >>> test_ushort(USHORT_MAX+1) #doctest: +ELLIPSIS
162 Traceback (most recent call last):
168 def test_add_ushort(x, y):
170 >>> test_add_ushort(USHORT_MAX, 0) == USHORT_MAX
172 >>> test_add_ushort(USHORT_MAX, 1) #doctest: +ELLIPSIS
173 Traceback (most recent call last):
177 cdef UShort r = x + y
180 # -------------------------------------------------------------------
182 SINT_MAX = <SInt>((<UInt>-1)>>1)
183 SINT_MIN = (-SINT_MAX-1)
185 def test_sint(int x):
187 >>> test_sint(SINT_MIN-1) #doctest: +ELLIPSIS
188 Traceback (most recent call last):
191 >>> test_sint(SINT_MIN) == SINT_MIN
199 >>> test_sint(SINT_MAX) == SINT_MAX
201 >>> test_sint(SINT_MAX+1) #doctest: +ELLIPSIS
202 Traceback (most recent call last):
208 def test_add_sint(x, y):
210 >>> test_add_sint(SINT_MIN, -1) #doctest: +ELLIPSIS
211 Traceback (most recent call last):
214 >>> test_add_sint(SINT_MIN, 0) == SINT_MIN
216 >>> test_add_sint(SINT_MIN, 1) == SINT_MIN+1
218 >>> test_add_sint(SINT_MAX, -1) == SINT_MAX-1
220 >>> test_add_sint(SINT_MAX, 0) == SINT_MAX
222 >>> test_add_sint(SINT_MAX, 1) #doctest: +ELLIPSIS
223 Traceback (most recent call last):
230 UINT_MAX = <UInt>(<UInt>-1)
232 def test_uint(UInt x):
234 >>> test_uint(-1) #doctest: +ELLIPSIS
235 Traceback (most recent call last):
238 >>> print(test_uint(0))
240 >>> print(test_uint(1))
242 >>> test_uint(UINT_MAX) == UINT_MAX
244 >>> test_uint(UINT_MAX+1) #doctest: +ELLIPSIS
245 Traceback (most recent call last):
251 def test_add_uint(x, y):
253 >>> test_add_uint(UINT_MAX, 0) == UINT_MAX
255 >>> test_add_uint(UINT_MAX, 1) #doctest: +ELLIPSIS
256 Traceback (most recent call last):
263 # -------------------------------------------------------------------
265 SLONG_MAX = <SLong>((<ULong>-1)>>1)
266 SLONG_MIN = (-SLONG_MAX-1)
268 def test_slong(long x):
270 >>> test_slong(SLONG_MIN-1) #doctest: +ELLIPSIS
271 Traceback (most recent call last):
274 >>> test_slong(SLONG_MIN) == SLONG_MIN
282 >>> test_slong(SLONG_MAX) == SLONG_MAX
284 >>> test_slong(SLONG_MAX+1) #doctest: +ELLIPSIS
285 Traceback (most recent call last):
291 def test_add_slong(x, y):
293 >>> test_add_slong(SLONG_MIN, -1) #doctest: +ELLIPSIS
294 Traceback (most recent call last):
297 >>> test_add_slong(SLONG_MIN, 0) == SLONG_MIN
299 >>> test_add_slong(SLONG_MIN, 1) == SLONG_MIN+1
301 >>> test_add_slong(SLONG_MAX, -1) == SLONG_MAX-1
303 >>> test_add_slong(SLONG_MAX, 0) == SLONG_MAX
305 >>> test_add_slong(SLONG_MAX, 1) #doctest: +ELLIPSIS
306 Traceback (most recent call last):
313 ULONG_MAX = <ULong>(<ULong>-1)
315 def test_ulong(ULong x):
317 >>> test_ulong(-1) #doctest: +ELLIPSIS
318 Traceback (most recent call last):
321 >>> print(test_ulong(0))
323 >>> print(test_ulong(1))
325 >>> test_ulong(ULONG_MAX) == ULONG_MAX
327 >>> test_ulong(ULONG_MAX+1) #doctest: +ELLIPSIS
328 Traceback (most recent call last):
334 def test_add_ulong(x, y):
336 >>> test_add_ulong(ULONG_MAX, 0) == ULONG_MAX
338 >>> test_add_ulong(ULONG_MAX, 1) #doctest: +ELLIPSIS
339 Traceback (most recent call last):
346 # -------------------------------------------------------------------
348 SLONGLONG_MAX = <SLongLong>((<ULongLong>-1)>>1)
349 SLONGLONG_MIN = (-SLONGLONG_MAX-1)
351 def test_slonglong(long long x):
353 >>> test_slonglong(SLONGLONG_MIN-1) #doctest: +ELLIPSIS
354 Traceback (most recent call last):
357 >>> test_slonglong(SLONGLONG_MIN) == SLONGLONG_MIN
359 >>> print(test_slonglong(-1))
361 >>> print(test_slonglong(0))
363 >>> print(test_slonglong(1))
365 >>> test_slonglong(SLONGLONG_MAX) == SLONGLONG_MAX
367 >>> test_slonglong(SLONGLONG_MAX+1) #doctest: +ELLIPSIS
368 Traceback (most recent call last):
374 def test_add_slonglong(x, y):
376 >>> test_add_slonglong(SLONGLONG_MIN, -1) #doctest: +ELLIPSIS
377 Traceback (most recent call last):
380 >>> test_add_slonglong(SLONGLONG_MIN, 0) == SLONGLONG_MIN
382 >>> test_add_slonglong(SLONGLONG_MIN, 1) == SLONGLONG_MIN+1
384 >>> test_add_slonglong(SLONGLONG_MAX, -1) == SLONGLONG_MAX-1
386 >>> test_add_slonglong(SLONGLONG_MAX, 0) == SLONGLONG_MAX
388 >>> test_add_slonglong(SLONGLONG_MAX, 1) #doctest: +ELLIPSIS
389 Traceback (most recent call last):
393 cdef SLongLong r = x + y
396 ULONGLONG_MAX = <ULongLong>(<ULongLong>-1)
398 def test_ulonglong(ULongLong x):
400 >>> test_ulonglong(-1) #doctest: +ELLIPSIS
401 Traceback (most recent call last):
404 >>> print(test_ulonglong(0))
406 >>> print(test_ulonglong(1))
408 >>> test_ulonglong(ULONGLONG_MAX) == ULONGLONG_MAX
410 >>> test_ulonglong(ULONGLONG_MAX+1) #doctest: +ELLIPSIS
411 Traceback (most recent call last):
417 def test_add_ulonglong(x, y):
419 >>> test_add_ulonglong(ULONGLONG_MAX, 0) == ULONGLONG_MAX
421 >>> test_add_ulonglong(ULONGLONG_MAX, 1) #doctest: +ELLIPSIS
422 Traceback (most recent call last):
426 cdef ULongLong r = x + y
429 # -------------------------------------------------------------------
435 >>> vals = (SCHAR_MIN, UCHAR_MAX,
436 ... SSHORT_MIN, USHORT_MAX,
437 ... SINT_MIN, UINT_MAX,
438 ... SLONG_MIN, ULONG_MAX,
439 ... SLONGLONG_MIN, ULONGLONG_MAX)
440 >>> a.setvalues(*vals)
441 >>> a.getvalues() == vals
444 >>> vals = (SCHAR_MAX, UCHAR_MAX,
445 ... SSHORT_MAX, USHORT_MAX,
446 ... SINT_MAX, UINT_MAX,
447 ... SLONG_MAX, ULONG_MAX,
448 ... SLONGLONG_MAX, ULONGLONG_MAX)
449 >>> a.setvalues(*vals)
450 >>> a.getvalues() == vals
454 >>> a.setvalues(*vals)
455 >>> a.getvalues() == vals
469 SLongLong attr_slonglong
470 ULongLong attr_ulonglong
472 cpdef setvalues(self,
481 SLongLong arg_slonglong ,
482 ULongLong arg_ulonglong ):
483 self.attr_schar = arg_schar
484 self.attr_uchar = arg_uchar
485 self.attr_sshort = arg_sshort
486 self.attr_ushort = arg_ushort
487 self.attr_sint = arg_sint
488 self.attr_uint = arg_uint
489 self.attr_slong = arg_slong
490 self.attr_ulong = arg_ulong
491 self.attr_slonglong = arg_slonglong
492 self.attr_ulonglong = arg_ulonglong
494 cpdef getvalues(self):
495 return (self.attr_schar ,
503 self.attr_slonglong ,
504 self.attr_ulonglong )
507 # -------------------------------------------------------------------
510 ctypedef signed MySInt1 "signed short"
511 ctypedef unsigned MyUInt1 "unsigned short"
513 def test_MySInt1(MySInt1 x):
524 def test_MyUInt1(MyUInt1 x):
526 >>> test_MyUInt1(-1) #doctest: +ELLIPSIS
527 Traceback (most recent call last):
538 ctypedef signed MySInt2 "signed short"
539 ctypedef unsigned MyUInt2 "unsigned short"
541 def test_MySInt2(MySInt2 x):
552 def test_MyUInt2(MyUInt2 x):
554 >>> test_MyUInt2(-1) #doctest: +ELLIPSIS
555 Traceback (most recent call last):
565 # -------------------------------------------------------------------
567 cimport ctypedef_int_types_defs_T333 as defs
569 def test_DefSInt(defs.SInt x):
580 def test_DefUChar(defs.UChar x):
582 >>> test_DefUChar(-1) #doctest: +ELLIPSIS
583 Traceback (most recent call last):
593 def test_ExtSInt(defs.ExtSInt x):
604 def test_ExtUInt(defs.ExtUInt x):
606 >>> test_ExtUInt(-1) #doctest: +ELLIPSIS
607 Traceback (most recent call last):
618 ctypedef defs.SShort LocSInt
619 ctypedef defs.UShort LocUInt
621 def test_LocSInt(LocSInt x):
632 def test_LocUInt(LocUInt x):
634 >>> test_LocUInt(-1) #doctest: +ELLIPSIS
635 Traceback (most recent call last):
645 # -------------------------------------------------------------------