New test case integers.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@8815 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
a5c2491f6a
commit
ca7f3bf836
5 changed files with 68 additions and 0 deletions
|
|
@ -357,6 +357,7 @@ C_TEST_CASES += \
|
|||
function_typedef \
|
||||
immutable \
|
||||
inctest \
|
||||
integers \
|
||||
lextype \
|
||||
li_carrays \
|
||||
li_cdata \
|
||||
|
|
|
|||
11
Examples/test-suite/guile/integers_runme.scm
Normal file
11
Examples/test-suite/guile/integers_runme.scm
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
;; The SWIG modules have "passive" Linkage, i.e., they don't generate
|
||||
;; Guile modules (namespaces) but simply put all the bindings into the
|
||||
;; current module. That's enough for such a simple test.
|
||||
(dynamic-call "scm_init_integers_module" (dynamic-link "./libintegers.so"))
|
||||
|
||||
(define-macro (throws-exception? form)
|
||||
`(catch #t
|
||||
(lambda () ,form #f)
|
||||
(lambda args #t)))
|
||||
|
||||
(load "../schemerunme/integers.scm")
|
||||
20
Examples/test-suite/integers.i
Normal file
20
Examples/test-suite/integers.i
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
/* This test case is meant to be used with run tests that check that
|
||||
-- the whole range of the integer types is supported;
|
||||
-- errors are signalled when out-of-range values are passed.
|
||||
*/
|
||||
|
||||
%module integers;
|
||||
|
||||
%inline %{
|
||||
signed char signed_char_identity(signed char x) { return x; }
|
||||
unsigned char unsigned_char_identity(unsigned char x) { return x; }
|
||||
signed short signed_short_identity(signed short x) { return x; }
|
||||
unsigned short unsigned_short_identity(unsigned short x) { return x; }
|
||||
signed int signed_int_identity(signed int x) { return x; }
|
||||
unsigned int unsigned_int_identity(unsigned int x) { return x; }
|
||||
signed long signed_long_identity(signed long x) { return x; }
|
||||
unsigned long unsigned_long_identity(unsigned long x) { return x; }
|
||||
signed long long signed_long_long_identity(signed long long x) { return x; }
|
||||
unsigned long long unsigned_long_long_identity(unsigned long long x) { return x; }
|
||||
%}
|
||||
|
||||
9
Examples/test-suite/mzscheme/integers_runme.scm
Normal file
9
Examples/test-suite/mzscheme/integers_runme.scm
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
(load-extension "integers.so")
|
||||
(require (lib "defmacro.ss"))
|
||||
|
||||
(define-macro (throws-exception? form)
|
||||
`(with-handlers ((not-break-exn? (lambda (exn) #t)))
|
||||
,form
|
||||
#f))
|
||||
|
||||
(load "../schemerunme/integers.scm")
|
||||
27
Examples/test-suite/schemerunme/integers.scm
Normal file
27
Examples/test-suite/schemerunme/integers.scm
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
(define-macro (check-equality form1 form2)
|
||||
`(let ((result1 ,form1)
|
||||
(result2 ,form2))
|
||||
(if (not (equal? result1 result2))
|
||||
(error "Check failed:"
|
||||
(list 'equal? ',form1 ',form2)
|
||||
result1 result2))))
|
||||
|
||||
(define-macro (check-range function from to)
|
||||
`(begin (check-equality (,function ,from) ,from)
|
||||
(check-equality (,function ,to) ,to)
|
||||
(check-equality (throws-exception? (- ,from 1)) #t)
|
||||
(check-equality (throws-exception? (+ ,to 1)) #t)))
|
||||
|
||||
;;; signed char, unsigned char typemaps deal with characters, not integers.
|
||||
;; (check-range signed-char-identity (- (expt 2 7)) (- (expt 2 7) 1))
|
||||
;; (check-range unsigned-char-identity 0 (- (expt 2 8) 1))
|
||||
(check-range signed-short-identity (- (expt 2 15)) (- (expt 2 15) 1))
|
||||
(check-range unsigned-short-identity 0 (- (expt 2 16) 1))
|
||||
(check-range signed-int-identity (- (expt 2 31)) (- (expt 2 31) 1))
|
||||
(check-range unsigned-int-identity 0 (- (expt 2 32) 1))
|
||||
(check-range signed-long-identity (- (expt 2 31)) (- (expt 2 31) 1))
|
||||
(check-range unsigned-long-identity 0 (- (expt 2 32) 1))
|
||||
;;; long long not implemented in Guile.
|
||||
;; (check-range signed-long-long-identity (- (expt 2 63)) (- (expt 2 63) 1))
|
||||
;; (check-range unsigned-long-long-identity 0 (- (expt 2 64) 1))
|
||||
(quit)
|
||||
Loading…
Add table
Add a link
Reference in a new issue