Initial commit

This commit is contained in:
Bassem Girgis
2018-12-20 17:34:07 -06:00
parent 7a2d899662
commit 81b4b9e273
34743 changed files with 5940233 additions and 0 deletions

View File

@@ -0,0 +1,65 @@
#######################################################################
# Makefile for guile test-suite
#######################################################################
EXTRA_TEST_CASES += guile_ext_test.externaltest
LANGUAGE = guile
VARIANT =
SCRIPTSUFFIX = _runme.scm
srcdir = @srcdir@
top_srcdir = @top_srcdir@
top_builddir = @top_builddir@
GUILE = @GUILE@
GUILE_RUNTIME=
C_TEST_CASES = long_long \
list_vector \
multivalue \
pointer_in_out
include $(srcdir)/../common.mk
# Overridden variables here
INCLUDES += -I$(top_srcdir)/$(EXAMPLES)/$(TEST_SUITE)/guile
# Custom tests - tests with additional commandline options
%.multicpptest: SWIGOPT += $(GUILE_RUNTIME)
# 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)
%.externaltest:
$(setup)
+$(swig_and_compile_external)
$(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 $(SCRIPTDIR)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX) ]; then \
env GUILE_AUTO_COMPILE=0 LD_LIBRARY_PATH=.:$$LD_LIBRARY_PATH $(RUNTOOL) $(GUILE) -l $(SCRIPTDIR)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX); \
fi
# Clean
%.clean:
@rm -f $*-guile
clean:
$(MAKE) -f $(top_builddir)/$(EXAMPLES)/Makefile SRCDIR='$(SRCDIR)' guile_clean

View File

@@ -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.

View File

@@ -0,0 +1,20 @@
;; tests support for native guile pointers
;; https://www.gnu.org/software/guile/manual/html_node/Void-Pointers-and-Byte-Access.html
(dynamic-call "scm_init_argout_module" (dynamic-link "./libargout"))
(define initial-value 42)
(define some-s32-data (s32vector initial-value))
;; if we're running guile 1.8, then bytevector->pointer won't exist and this
;; test is useless
(if (>= (string->number (major-version)) 2)
(begin
(use-modules (srfi srfi-4) (system foreign))
(if (not (= (incp (bytevector->pointer some-s32-data)) initial-value))
(error "Didn't read s32 data" initial-value some-s32-data))
(if (not (= (s32vector-ref some-s32-data 0) (+ initial-value 1)))
(error "Failed to increment s32 data" some-s32-data))))
(exit 0)

View File

@@ -0,0 +1,5 @@
;; 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_casts_module" (dynamic-link "./libcasts"))
(load "../schemerunme/casts.scm")

View File

@@ -0,0 +1,5 @@
;; 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_char_constant_module" (dynamic-link "./libchar_constant"))
(load "../schemerunme/char_constant.scm")

View File

@@ -0,0 +1,2 @@
(dynamic-call "scm_init_class_ignore_module" (dynamic-link "./libclass_ignore"))
(load "../schemerunme/class_ignore.scm")

View File

@@ -0,0 +1,2 @@
(dynamic-call "scm_init_constover_module" (dynamic-link "./libconstover"))
(load "../schemerunme/constover.scm")

View File

@@ -0,0 +1,6 @@
;; 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_contract_module" (dynamic-link "./libcontract"))
(load "testsuite.scm")
(load "../schemerunme/contract.scm")

View File

@@ -0,0 +1,5 @@
;; 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_cpp_enum_module" (dynamic-link "./libcpp_enum"))
(load "../schemerunme/cpp_enum.scm")

View File

@@ -0,0 +1,2 @@
(dynamic-call "scm_init_cpp_namespace_module" (dynamic-link "./libcpp_namespace"))
(load "../schemerunme/cpp_namespace.scm")

View File

@@ -0,0 +1,2 @@
(dynamic-call "scm_init_dynamic_cast_module" (dynamic-link "./libdynamic_cast"))
(load "../schemerunme/dynamic_cast.scm")

View File

@@ -0,0 +1,24 @@
#include <guile_ext_test_wrap_hdr.h>
#include <imports_a.h>
SCM test_create()
{
#define FUNC_NAME "test-create"
SCM result;
A *newobj;
swig_type_info *type;
newobj = new A();
type = SWIG_TypeQuery("A *");
result = SWIG_NewPointerObj(newobj, type, 1);
return result;
#undef FUNC_NAME
}
SCM test_is_pointer(SCM val)
{
#define FUNC_NAME "test-is-pointer"
return SCM_BOOL(SWIG_IsPointer(val));
#undef FUNC_NAME
}

View File

@@ -0,0 +1,19 @@
(dynamic-call "scm_init_guile_ext_test_module" (dynamic-link "./libguile_ext_test"))
; This is a test for SF Bug 1573892
; If IsPointer is called before TypeQuery, the test-is-pointer will fail
; (i.e if the bottom two lines were moved to the top, the old code would succeed)
; only a problem when is-pointer is called first
(define a (new-A))
(if (not (test-is-pointer a))
(error "test-is-pointer failed!"))
(if (test-is-pointer 5)
(error "test-is-pointer thinks 5 is a pointer!"))
(define b (test-create))
(A-hello b)
(exit 0)

View File

@@ -0,0 +1,2 @@
(dynamic-call "scm_init_import_nomodule_module" (dynamic-link "./libimport_nomodule"))
(load "../schemerunme/import_nomodule.scm")

View File

@@ -0,0 +1,11 @@
;;; 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"))
(dynamic-call "scm_init_imports_b_module" (dynamic-link "./libimports_b"))
(load "../schemerunme/imports.scm")

View File

@@ -0,0 +1,2 @@
(dynamic-call "scm_init_inherit_missing_module" (dynamic-link "./libinherit_missing"))
(load "../schemerunme/inherit_missing.scm")

View 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"))
(define-macro (throws-exception? form)
`(catch #t
(lambda () ,form #f)
(lambda args #t)))
(load "../schemerunme/integers.scm")

View File

@@ -0,0 +1,32 @@
;; 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_li_std_string_module" (dynamic-link "./libli_std_string"))
; Note: when working with non-ascii strings in guile 2
; Guile doesn't handle non-ascii characters in the default C locale
; The locale must be set explicitly
; The setlocale call below takes care of that
; The locale needs to be a UTF-8 locale to handle the non-ASCII characters
; But they are named differently on different systems so we try a few until one works
(define (try-set-locale name)
; (display "testing ")
; (display name)
; (display "\n")
(catch #t
(lambda ()
(setlocale LC_ALL name)
#t
)
(lambda (key . parameters)
#f
))
)
(if (not (try-set-locale "C.UTF-8")) ; Linux
(if (not (try-set-locale "en_US.utf8")) ; Linux
(if (not (try-set-locale "en_US.UTF-8")) ; Mac OS X
(error "Failed to set any UTF-8 locale")
)))
(load "../schemerunme/li_std_string.scm")

View File

@@ -0,0 +1,18 @@
;;; 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_li_typemaps_module" (dynamic-link "./libli_typemaps"))
(load "../schemerunme/li_typemaps.scm")
(let ((lst (inoutr-int2 3 -2)))
(if (not (and (= (car lst) 3) (= (cadr lst) -2)))
(error "Error in inoutr-int2")))
(let ((lst (out-foo 4)))
(if (not (and (= (Foo-a-get (car lst)) 4) (= (cadr lst) 8)))
(error "Error in out-foo")))
(exit 0)

View File

@@ -0,0 +1,5 @@
;; 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_list_vector_module" (dynamic-link "./liblist_vector"))
(load "../schemerunme/list_vector.scm")

View File

@@ -0,0 +1,7 @@
;;;; 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_multivalue_module" (dynamic-link "./libmultivalue"))
(load "../schemerunme/multivalue.scm")

View File

@@ -0,0 +1,5 @@
;; 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_name_module" (dynamic-link "./libname"))
(load "../schemerunme/name.scm")

View File

@@ -0,0 +1,21 @@
;; 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"))
(define-macro (check form)
`(if (not ,form)
(error "Check failed: " ',form)))
(define (=~ a b)
(< (abs (- a b)) 1e-8))
;; 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)

View File

@@ -0,0 +1,2 @@
(dynamic-call "scm_init_overload_copy_module" (dynamic-link "./liboverload_copy"))
(load "../schemerunme/overload_copy.scm")

View File

@@ -0,0 +1,2 @@
(dynamic-call "scm_init_overload_extend_c_module" (dynamic-link "./liboverload_extend_c"))
(load "../schemerunme/overload_extend_c.scm")

View File

@@ -0,0 +1,2 @@
(dynamic-call "scm_init_overload_extend_module" (dynamic-link "./liboverload_extend"))
(load "../schemerunme/overload_extend.scm")

View File

@@ -0,0 +1,5 @@
;; 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"))
(load "../schemerunme/overload_simple.scm")

View File

@@ -0,0 +1,5 @@
;; 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"))
(load "../schemerunme/overload_subtype.scm")

View File

@@ -0,0 +1,5 @@
;; 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"))
(load "../schemerunme/pointer_in_out.scm")

View File

@@ -0,0 +1,3 @@
; copied from python runme_.py
(dynamic-call "scm_init_reference_global_vars_module" (dynamic-link "./libreference_global_vars"))
(load "../schemerunme/reference_global_vars.scm")

View File

@@ -0,0 +1,37 @@
;; Little helper functions and macros for the run tests
(use-modules (ice-9 format))
(define (test-error error-format . args)
(display "Runtime check failed. ")
(apply format #t error-format args)
(newline)
(exit 1))
(define-macro (expect-true form)
`(if (not ,form)
(test-error "Expected true value of ~A" ',form)))
(define-macro (expect-false form)
`(if ,form
(test-error "Expected false value of ~A" ',form)))
(define-macro (expect-result expected-result-form equal? form)
`(let ((expected-result ,expected-result-form)
(result ,form))
(if (not (,equal? result expected-result))
(test-error "The result of ~A was ~A, expected ~A, which is not ~A"
',form result expected-result ',equal?))))
(define-macro (expect-throw tag-form form)
`(let ((tag ,tag-form))
(if (catch #t
(lambda ()
,form
#t)
(lambda (key . args)
(if (eq? key ,tag-form)
#f
(test-error "The form ~A threw to ~A (expected a throw to ~A)"
',form key tag))))
(test-error "The form ~A returned normally (expected a throw to ~A)"))))

View File

@@ -0,0 +1,45 @@
;; 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_throw_exception_module" (dynamic-link "./libthrow_exception"))
(define-macro (check-throw form)
`(catch 'swig-exception
(lambda ()
,form
(error "Check failed (returned normally): " ',form))
(lambda (key result)
result)))
(define-macro (check-throw-error form)
`(let ((result (check-throw ,form)))
(test-is-Error result)))
(let ((foo (new-Foo)))
(let ((result (check-throw (Foo-test-int foo))))
(if (not (eqv? result 37))
(error "Foo-test-int failed, returned " result)))
(let ((result (check-throw (Foo-test-multi foo 1))))
(if (not (eqv? result 37))
(error "Foo-test-multi 1 failed, returned " result)))
(let ((result (check-throw (Foo-test-msg foo))))
(if (not (and (string? result)
(string=? result "Dead")))
(error "Foo-test-msg failed, returned " result)))
(let ((result (check-throw (Foo-test-multi foo 2))))
(if (not (and (string? result)
(string=? result "Dead")))
(error "Foo-test-multi 2 failed, returned " result)))
(check-throw-error (Foo-test-cls foo))
(check-throw-error (Foo-test-multi foo 3))
(check-throw-error (Foo-test-cls-ptr foo))
(check-throw-error (Foo-test-cls-ref foo))
;; Namespace stuff
(let ((result (check-throw (Foo-test-enum foo))))
(if (not (eqv? result (enum2)))
(error "Foo-test-enum failed, returned " result)))
(check-throw-error (Foo-test-cls-td foo))
(check-throw-error (Foo-test-cls-ptr-td foo))
(check-throw-error (Foo-test-cls-ref-td foo)))
(exit 0)

View File

@@ -0,0 +1,2 @@
(dynamic-call "scm_init_typedef_inherit_module" (dynamic-link "./libtypedef_inherit"))
(load "../schemerunme/typedef_inherit.scm")

View File

@@ -0,0 +1,3 @@
(dynamic-call "scm_init_typename_module" (dynamic-link "./libtypename"))
;;(dynamic-call "scm_init_types_module" (dynamic-link "./libtypes"))
(load "../schemerunme/typename.scm")

View File

@@ -0,0 +1,8 @@
;;; 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"))
(load "../schemerunme/unions.scm")