diff options
Diffstat (limited to 'Examples/test-suite/guile')
-rw-r--r-- | Examples/test-suite/guile/.cvsignore | 2 | ||||
-rw-r--r-- | Examples/test-suite/guile/Makefile | 44 | ||||
-rw-r--r-- | Examples/test-suite/guile/README | 4 | ||||
-rw-r--r-- | Examples/test-suite/guile/casts_runme.scm | 13 | ||||
-rw-r--r-- | Examples/test-suite/guile/char_constant_runme.scm | 9 | ||||
-rw-r--r-- | Examples/test-suite/guile/imports_runme.scm | 19 | ||||
-rw-r--r-- | Examples/test-suite/guile/list_vector_runme.scm | 28 | ||||
-rw-r--r-- | Examples/test-suite/guile/multivalue_runme.scm | 24 | ||||
-rw-r--r-- | Examples/test-suite/guile/name_runme.scm | 10 | ||||
-rw-r--r-- | Examples/test-suite/guile/overload_complicated_runme.scm | 18 | ||||
-rw-r--r-- | Examples/test-suite/guile/overload_simple_runme.scm | 56 | ||||
-rw-r--r-- | Examples/test-suite/guile/overload_subtype_runme.scm | 12 | ||||
-rw-r--r-- | Examples/test-suite/guile/pointer_in_out_runme.scm | 18 | ||||
-rw-r--r-- | Examples/test-suite/guile/unions_runme.scm | 41 |
14 files changed, 298 insertions, 0 deletions
diff --git a/Examples/test-suite/guile/.cvsignore b/Examples/test-suite/guile/.cvsignore new file mode 100644 index 000000000..1242e8c7e --- /dev/null +++ b/Examples/test-suite/guile/.cvsignore @@ -0,0 +1,2 @@ +*wrap* +*-guile diff --git a/Examples/test-suite/guile/Makefile b/Examples/test-suite/guile/Makefile new file mode 100644 index 000000000..a39bcaf0e --- /dev/null +++ b/Examples/test-suite/guile/Makefile @@ -0,0 +1,44 @@ +####################################################################### +# $Header$ +# Makefile for guile test-suite +####################################################################### + +LANGUAGE = guile +VARIANT = _passive +SCRIPTSUFFIX = _runme.scm + +C_TEST_CASES = long_long list_vector pointer_in_out multivalue + +include ../common.mk + +# Overridden variables here + +# Rules for the different types of tests +%.cpptest: + $(setup) \ + ($(swig_and_compile_cpp); ); \ + $(run_testcase) + +%.ctest: + $(setup) \ + ($(swig_and_compile_c); ); \ + $(run_testcase) + +%.multicpptest: + $(setup) \ + ($(swig_and_compile_multi_cpp); ); \ + $(run_testcase) + +# Runs the testcase. A testcase is only run if +# a file is found which has _runme.scm appended after the testcase name. +run_testcase = \ + if [ -f $*\_runme.scm ]; then ( \ + env LD_LIBRARY_PATH=$(DYNAMIC_LIB_PATH):$$LD_LIBRARY_PATH guile -l $*\_runme.scm;) \ + fi; + +# Clean +%.clean: + @rm -f $*-guile + +clean: + $(MAKE) -f $(TOP)/Makefile guile_clean diff --git a/Examples/test-suite/guile/README b/Examples/test-suite/guile/README new file mode 100644 index 000000000..37432ea4b --- /dev/null +++ b/Examples/test-suite/guile/README @@ -0,0 +1,4 @@ +See ../README for common README file. + +Any testcases which have _runme.scm appended after the testcase name will be detected and run. + diff --git a/Examples/test-suite/guile/casts_runme.scm b/Examples/test-suite/guile/casts_runme.scm new file mode 100644 index 000000000..17e7725f6 --- /dev/null +++ b/Examples/test-suite/guile/casts_runme.scm @@ -0,0 +1,13 @@ +;; 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_test_module" (dynamic-link "./libcasts.so")) + +(define x (new-B)) + +;; This fails in 1.3a5 because the SWIG/Guile runtime code gets the +;; source and the target of a cast the wrong way around. + +(A-hello x) + +(exit 0) diff --git a/Examples/test-suite/guile/char_constant_runme.scm b/Examples/test-suite/guile/char_constant_runme.scm new file mode 100644 index 000000000..2cc89b051 --- /dev/null +++ b/Examples/test-suite/guile/char_constant_runme.scm @@ -0,0 +1,9 @@ +;; 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_test_module" (dynamic-link "./libchar_constant.so")) + +(if (and (char? (CHAR-CONSTANT)) + (string? (STRING-CONSTANT))) + (exit 0) + (exit 1)) diff --git a/Examples/test-suite/guile/imports_runme.scm b/Examples/test-suite/guile/imports_runme.scm new file mode 100644 index 000000000..030fbfd61 --- /dev/null +++ b/Examples/test-suite/guile/imports_runme.scm @@ -0,0 +1,19 @@ +;;; This file is part of a test for SF bug #231619. +;;; It shows that the %import directive does not work properly in SWIG +;;; 1.3a5: Type information is not properly generated if a base class +;;; comes from an %import-ed file. + +;; 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_imports_a_module" (dynamic-link "./libimports_a.so")) +(dynamic-call "scm_init_imports_b_module" (dynamic-link "./libimports_b.so")) + +(define x (new-B)) + +;; This fails in 1.3a5 because the SWIG runtime code does not know +;; that x (an instance of class B) can be passed to methods of class A. + +(A-hello x) + +(exit 0) diff --git a/Examples/test-suite/guile/list_vector_runme.scm b/Examples/test-suite/guile/list_vector_runme.scm new file mode 100644 index 000000000..1957c9a7f --- /dev/null +++ b/Examples/test-suite/guile/list_vector_runme.scm @@ -0,0 +1,28 @@ +;; 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_test_module" (dynamic-link "./liblist_vector.so")) + +(define-macro (check form) + `(if (not ,form) + (error "Check failed: " ',form))) + +(check (= (sum-list '(1 3 4 6 7)) 21)) +(check (= (sum-vector #(2 4 6 7 9)) 28)) +(check (equal? (one-to-seven-list) '(1 2 3 4 5 6 7))) +(check (equal? (one-to-seven-vector) #(1 2 3 4 5 6 7))) + +(check (= (sum-list2 '(1 3 4 6 7)) 21)) +(check (= (sum-vector2 #(2 4 6 7 9)) 28)) +(check (equal? (one-to-seven-list2) '(1 2 3 4 5 6 7))) +(check (equal? (one-to-seven-vector2) #(1 2 3 4 5 6 7))) + +(check (= (sum-lists '(1 2 3) '(4 5 6) '(7 8 9)) 45)) +(check (= (sum-lists2 '(1 2 3) '(4 5 6) '(7 8 9)) 45)) +(check (equal? (call-with-values produce-lists list) + '(#(0 1 2 3 4) + #(0 1 4 9 16) + #(0.0 1.5 3.0 4.5 6.0)))) + + +(exit 0) diff --git a/Examples/test-suite/guile/multivalue_runme.scm b/Examples/test-suite/guile/multivalue_runme.scm new file mode 100644 index 000000000..910935801 --- /dev/null +++ b/Examples/test-suite/guile/multivalue_runme.scm @@ -0,0 +1,24 @@ +;;;; Automatic test of multiple return values + +;; 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_test_module" (dynamic-link "./libmultivalue.so")) + +(let ((quotient/remainder (divide-l 37 5))) + (if (not (equal? quotient/remainder '(7 2))) + (exit 1))) + +(let ((quotient-remainder-vector (divide-v 41 7))) + (if (not (equal? quotient-remainder-vector #(5 6))) + (exit 1))) + +(call-with-values (lambda () + (divide-mv 91 13)) + (lambda (quotient remainder) + (if (not (and (= quotient 7) + (= remainder 0))) + (exit 1)))) + +(exit 0) + diff --git a/Examples/test-suite/guile/name_runme.scm b/Examples/test-suite/guile/name_runme.scm new file mode 100644 index 000000000..a7121b9d9 --- /dev/null +++ b/Examples/test-suite/guile/name_runme.scm @@ -0,0 +1,10 @@ +;; 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_test_module" (dynamic-link "./libname.so")) + +(foo-2) +bar-2 +Baz-2 + +(exit 0) diff --git a/Examples/test-suite/guile/overload_complicated_runme.scm b/Examples/test-suite/guile/overload_complicated_runme.scm new file mode 100644 index 000000000..0423aafbd --- /dev/null +++ b/Examples/test-suite/guile/overload_complicated_runme.scm @@ -0,0 +1,18 @@ +;; 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_overload_complicated_module" (dynamic-link "./liboverload_complicated.so")) + +(define-macro (check form) + `(if (not ,form) + (error "Check failed: " ',form))) + +;; Check first method +(check (= (foo 1 2 "bar" 4) 15)) + +;; Check second method +(check (= (foo 1 2) 4811.4)) +(check (= (foo 1 2 3.2) 4797.2)) +(check (= (foo 1 2 3.2 #\Q) 4798.2)) + +(exit 0) diff --git a/Examples/test-suite/guile/overload_simple_runme.scm b/Examples/test-suite/guile/overload_simple_runme.scm new file mode 100644 index 000000000..abe95069a --- /dev/null +++ b/Examples/test-suite/guile/overload_simple_runme.scm @@ -0,0 +1,56 @@ +;; 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_overload_simple_module" (dynamic-link "./liboverload_simple.so")) + +(if (not (string=? (foo 3) "foo:int")) + (error "foo(int)")) + +(if (not (string=? (foo 3.01) "foo:double")) + (error "foo(double)")) + +(if (not (string=? (foo "hello") "foo:char *")) + (error "foo(char *)")) + +(let ((f (new-Foo)) + (b (new-Bar)) + (s (new-Spam))) + (if (not (string=? (foo f) "foo:Foo *")) + (error "foo(Foo *)")) + (if (not (string=? (foo b) "foo:Bar *")) + (error "foo(Bar *)")) + ;; Test member functions + (if (not (string=? (Spam-foo s 3) "foo:int")) + (error "Spam::foo(int)")) + (if (not (string=? (Spam-foo s 3.01) "foo:double")) + (error "Spam::foo(double)")) + (if (not (string=? (Spam-foo s "hello") "foo:char *")) + (error "Spam::foo(char *)")) + (if (not (string=? (Spam-foo s f) "foo:Foo *")) + (error "Spam::foo(Foo *)")) + (if (not (string=? (Spam-foo s b) "foo:Bar *")) + (error "Spam::foo(Bar *)")) + ;; Test static member functions + (if (not (string=? (Spam-bar 3) "bar:int")) + (error "Spam::bar(int)")) + (if (not (string=? (Spam-bar 3.01) "bar:double")) + (error "Spam::bar(double)")) + (if (not (string=? (Spam-bar "hello") "bar:char *")) + (error "Spam::bar(char *)")) + (if (not (string=? (Spam-bar f) "bar:Foo *")) + (error "Spam::bar(Foo *)")) + (if (not (string=? (Spam-bar b) "bar:Bar *")) + (error "Spam::bar(Bar *)")) + ;; Test constructors + (if (not (string=? (Spam-type-get (new-Spam)) "none")) + (error "Spam()")) + (if (not (string=? (Spam-type-get (new-Spam 3)) "int")) + (error "Spam(int)")) + (if (not (string=? (Spam-type-get (new-Spam 3.4)) "double")) + (error "Spam(double)")) + (if (not (string=? (Spam-type-get (new-Spam "hello")) "char *")) + (error "Spam(char *)")) + (if (not (string=? (Spam-type-get (new-Spam b)) "Bar *")) + (error "Spam(Bar *)"))) + +(exit 0) diff --git a/Examples/test-suite/guile/overload_subtype_runme.scm b/Examples/test-suite/guile/overload_subtype_runme.scm new file mode 100644 index 000000000..14737f144 --- /dev/null +++ b/Examples/test-suite/guile/overload_subtype_runme.scm @@ -0,0 +1,12 @@ +;; 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_overload_subtype_module" (dynamic-link "./liboverload_subtype.so")) + +(if (not (= (spam (new-Foo)) 1)) + (error "foo")) + +(if (not (= (spam (new-Bar)) 2)) + (error "bar")) + +(exit 0) diff --git a/Examples/test-suite/guile/pointer_in_out_runme.scm b/Examples/test-suite/guile/pointer_in_out_runme.scm new file mode 100644 index 000000000..68ce0aa3b --- /dev/null +++ b/Examples/test-suite/guile/pointer_in_out_runme.scm @@ -0,0 +1,18 @@ +;; 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_pointer_in_out_module" (dynamic-link "./libpointer_in_out.so")) + +(define-macro (check form) + `(if (not ,form) + (error "Check failed: " ',form))) + +(define p (produce-int-pointer 47 11)) + +(check (= (consume-int-pointer p) 47)) + +(define q (frobnicate-int-pointer p)) + +(check (= (consume-int-pointer q) 11)) + +(exit 0) diff --git a/Examples/test-suite/guile/unions_runme.scm b/Examples/test-suite/guile/unions_runme.scm new file mode 100644 index 000000000..ce2caa8b3 --- /dev/null +++ b/Examples/test-suite/guile/unions_runme.scm @@ -0,0 +1,41 @@ +;;; This is the union runtime testcase. It ensures that values within a +;;; union embedded within a struct can be set and read correctly. + +;; 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_unions_module" (dynamic-link "./libunions.so")) + +;; Create new instances of SmallStruct and BigStruct for later use +(define small (new-SmallStruct)) +(SmallStruct-jill-set small 200) + +(define big (new-BigStruct)) +(BigStruct-smallstruct-set big small) +(BigStruct-jack-set big 300) + +;; Use SmallStruct then BigStruct to setup EmbeddedUnionTest. +;; Ensure values in EmbeddedUnionTest are set correctly for each. +(define eut (new-EmbeddedUnionTest)) + +;; First check the SmallStruct in EmbeddedUnionTest +(EmbeddedUnionTest-number-set eut 1) +(EmbeddedUnionTest-uni-small-set (EmbeddedUnionTest-uni-get eut) + small) +(let ((Jill1 (SmallStruct-jill-get + (EmbeddedUnionTest-uni-small-get + (EmbeddedUnionTest-uni-get eut))))) + (if (not (= Jill1 200)) + (begin + (display "Runtime test 1 failed.") + (exit 1)))) + +(let ((Num1 (EmbeddedUnionTest-number-get eut))) + (if (not (= Num1 1)) + (begin + (display "Runtime test 2 failed.") + (exit 1)))) + +;; that should do + +(exit 0) |