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,77 @@
#######################################################################
# Makefile for ocaml test-suite
#######################################################################
LANGUAGE = ocaml
OCAMLC = @OCAMLC@
VARIANT = _static
SCRIPTSUFFIX = _runme.ml
srcdir = @srcdir@
top_srcdir = @top_srcdir@
top_builddir = @top_builddir@
C_TEST_CASES =
run_testcase = \
if [ -f $(SCRIPTDIR)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX) -a \
-f $(top_srcdir)/Examples/test-suite/$*.list ] ; then \
$(COMPILETOOL) $(OCAMLC) -c $(SCRIPTDIR)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX); \
$(COMPILETOOL) $(OCAMLC) swig.cmo -custom -g -cc '$(CXX)' -o runme `cat $(top_srcdir)/Examples/test-suite/$(*).list | sed -e 's/\(.*\)/\1_wrap.o \1.cmo/g'`&& $(RUNTOOL) ./runme; \
elif [ -f $(SCRIPTDIR)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX) ]; then \
$(COMPILETOOL) $(OCAMLC) -c $(SCRIPTDIR)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX); \
$(COMPILETOOL) $(OCAMLC) swig.cmo -custom -g -cc '$(CXX)' -o runme $(srcdir)/$(*).cmo $(srcdir)/$(*)_runme.cmo $(srcdir)/$(*)_wrap.o && \
$(RUNTOOL) ./runme; \
fi ;
check_quant:
: > testing
: > success
$(MAKE) check
echo "Failed:" > results
diff testing success | sed 's/^< //p;d' >> results
echo "Success:" >> results
cat success >> results
include $(srcdir)/../common.mk
# Overridden variables here
# none!
# Custom tests - tests with additional commandline options
# none!
# Rules for the different types of tests
%.cpptest:
echo $@ >> testing
$(setup)
+$(swig_and_compile_cpp)
$(run_testcase)
if [ -f $(@:%.cpptest=%_wrap.o) ] ; then \
echo $@ >> success ; \
fi
%.ctest:
echo $@ >> testing
$(setup)
+$(swig_and_compile_c)
$(run_testcase)
if [ -f $(@:%.ctest=%_wrap.o) ] ; then \
echo $@ >> success ; \
fi
%.multicpptest:
echo $@ >> testing
+$(swig_and_compile_multi_cpp)
$(setup)
$(run_testcase)
if [ -f $(@:%.multicpptest=%_runtime_wrap.o) ] ; then \
echo $@ >> success ; \
fi
# Clean
%.clean:
@rm -f $*.ml $*.mli;
clean:
$(MAKE) -f $(top_builddir)/$(EXAMPLES)/Makefile SRCDIR='$(SRCDIR)' ocaml_clean

View File

@@ -0,0 +1,2 @@
I stole most of these runme's from the ruby runme scripts, since the current
ocaml interface mirrors the ruby interface in many ways.

View File

@@ -0,0 +1,7 @@
open Swig
open Class_ignore
let a = new_Bar C_void
let _ = (if _do_blah a <> C_string "Bar::blah" then
raise (Failure "We didn't really get a bar object."))

View File

@@ -0,0 +1,10 @@
(* purpose: to receive the hello A method from Imports_a exposed through
* a B object derived from A *)
open Swig
open Imports_a
open Imports_b
let x = new_B C_void
(* Tests conversion of x to a generic value *)
let a = swig_val `unknown x
let _ = (invoke x) "hello" C_void

View File

@@ -0,0 +1,21 @@
#!/bin/sh
#
# Usage: makedebugtop test_name.c[pp]test
#
# Creates an ocaml toplevel for debugging based on a .cpptest or .ctest
# file.
#
OCAMLINC=/usr/local/lib/ocaml
swigtest=$1
thetest=`echo $1 | sed -e 's/\.c[p]*test//g'`
cppopt=""
if echo $swigtest | grep -s cpptest ; then
cppopt=-xc++
fi
echo "Making the test"
make $swigtest
echo "Building ${thetest}_top"
gcc -c -g $cppopt -I$OCAMLINC ${thetest}_wrap.c
ocamlmktop -cclib -g -custom swig.cmo ${thetest}_wrap.o ${thetest}.cmo -o ${thetest}_top -cclib -lstdc++

View File

@@ -0,0 +1,131 @@
(* Stolen from the python tests *)
open Swig
open Minherit
let a = new_Foo C_void
let b = new_Bar C_void
let c = new_FooBar C_void
let d = new_Spam C_void
let soci x = (string_of_int (get_int x))
let _ =
if (invoke a) "xget" C_void <> (C_int 1) then
raise (Failure "Bad attribute value (a.xget)")
let _ =
if (invoke b) "yget" C_void <> (C_int 2) then
raise (Failure "Bad attribute value (b.yget)")
let _ =
if (invoke c) "xget" C_void <> (C_int 1)
|| (invoke c) "yget" C_void <> (C_int 2)
|| (invoke c) "zget" C_void <> (C_int 3) then
raise (Failure "Bad attribute value c")
let _ =
if (invoke d) "xget" C_void <> (C_int 1)
|| (invoke d) "yget" C_void <> (C_int 2)
|| (invoke d) "zget" C_void <> (C_int 3)
|| (invoke d) "wget" C_void <> (C_int 4) then
raise (Failure "Bad attribute value d")
let xga = _xget a
let _ =
if xga <> (C_int 1) then
raise (Failure ("Bad attribute value (xget a): " ^ (soci xga)))
let ygb = _yget b
let _ =
if ygb <> (C_int 2) then
raise (Failure ("Bad attribute value (yget b): " ^
(string_of_int (get_int ygb))))
let xgc = _xget c and ygc = _yget c and zgc = _zget c
let _ =
if xgc <> (C_int 1) || ygc <> (C_int 2) || zgc <> (C_int 3) then
raise (Failure ("Bad attribute value (xgc=" ^ (soci xgc) ^
" (sb 1) ygc=" ^ (soci ygc) ^
" (sb 2) zgc=" ^ (soci zgc) ^
" (sb 3))"))
let xgd = _xget d and ygd = _yget d and zgd = _zget d and wgd = _wget d
let _ =
if xgd <> (C_int 1) || ygd <> (C_int 2)
|| zgd <> (C_int 3) || wgd <> (C_int 4) then
raise (Failure ("Bad attribute value (xgd=" ^ (soci xgd) ^
" (sb 1) ygd=" ^ (soci ygd) ^
" (sb 2) zgd=" ^ (soci zgd) ^
" (sb 3)"))
(* Cleanse all of the pointers and see what happens *)
let aa = _toFooPtr a
let bb = _toBarPtr b
let cc = _toFooBarPtr c
let dd = _toSpamPtr d
let xgaa = (invoke aa) "xget" C_void
let _ =
if xgaa <> (C_int 1) then
raise (Failure ("Bad attribute value xgaa " ^ (soci xgaa)))
let ygbb = (invoke bb) "yget" C_void
let _ =
if ygbb <> (C_int 2) then
raise (Failure ("Bad attribute value ygbb " ^ (soci ygbb)))
let xgcc = (invoke cc) "xget" C_void
and ygcc = (invoke cc) "yget" C_void
and zgcc = (invoke cc) "zget" C_void
let _ =
if xgcc <> (C_int 1) || ygcc <> (C_int 2) || zgcc <> (C_int 3) then
raise (Failure ("Bad attribute value (" ^
(soci xgcc) ^ " (sb 1) " ^
(soci ygcc) ^ " (sb 2) " ^
(soci zgcc) ^ " (sb 3))"))
let xgdd = (invoke dd) "xget" C_void
and ygdd = (invoke dd) "yget" C_void
and zgdd = (invoke dd) "zget" C_void
and wgdd = (invoke dd) "wget" C_void
let _ =
if xgdd <> (C_int 1) || ygdd <> (C_int 2)
|| zgdd <> (C_int 3) || wgdd <> (C_int 4) then
raise (Failure ("Bad value: " ^
"xgdd=" ^ (soci xgdd) ^
"ygdd=" ^ (soci ygdd) ^
"zgdd=" ^ (soci zgdd) ^
"wgdd=" ^ (soci wgdd)))
let xgaa = _xget aa
and ygbb = _yget bb
and xgcc = _xget cc
and ygcc = _yget cc
and zgcc = _zget cc
and xgdd = _xget dd
and ygdd = _yget dd
and zgdd = _zget dd
and wgdd = _wget dd
let _ =
if xgaa <> (C_int 1) then
raise (Failure ("Fn xget: xgaa=" ^ (soci xgaa)))
let _ =
if ygbb <> (C_int 2) then
raise (Failure ("Fn yget: ygbb=" ^ (soci ygbb)))
let _ =
if xgcc <> (C_int 1) || ygcc <> (C_int 2) || zgcc <> (C_int 3) then
raise (Failure ("CC with fns: (" ^
(soci xgcc) ^ " " ^ (soci ygcc) ^ " " ^ (soci zgcc)))
let _ =
if xgdd <> (C_int 1) || ygdd <> (C_int 2)
|| zgdd <> (C_int 3) || wgdd <> (C_int 4) then
raise (Failure ("CC with fns: (" ^
(soci xgdd) ^ " " ^ (soci ygdd) ^ " " ^
(soci zgdd) ^ " " ^ (soci wgdd) ^ ")"))

View File

@@ -0,0 +1,9 @@
open Swig
open Name
let _ = if (get_int (_Baz_2 C_void)) - (get_int (_bar_2 C_void)) == 30
then
exit 0
else
exit 1

View File

@@ -0,0 +1,26 @@
open Swig
open Newobject1
exception RuntimeError of string * int
let foo1 = ref (_Foo_makeFoo C_void)
let _ = if get_int (_Foo_fooCount C_void) != 1 then
raise (RuntimeError ("(1) Foo.fooCount != 1",
get_int (_Foo_fooCount C_void)))
let foo2 = ref ((invoke !foo1) "makeMore" C_void)
let _ = if get_int (_Foo_fooCount C_void) != 2 then
raise (RuntimeError ("(2) Foo.fooCount != 2",
get_int (_Foo_fooCount C_void)))
let _ = begin
foo1 := C_void ; Gc.full_major () ;
(if get_int (_Foo_fooCount C_void) != 1 then
raise (RuntimeError ("(3) Foo.fooCount != 1",
get_int (_Foo_fooCount C_void)))) ;
foo2 := C_void ; Gc.full_major () ;
(if get_int (_Foo_fooCount C_void) != 0 then
raise (RuntimeError ("(4) Foo.fooCount != 0",
get_int (_Foo_fooCount C_void)))) ;
end

View File

@@ -0,0 +1,5 @@
open Swig
open Overload_copy
let f = new_Foo C_void
let g = new_Foo f

View File

@@ -0,0 +1,9 @@
(* Stolen from ruby test cases *)
open Swig
open Sneaky1
let x = Sneaky1._add (C_list [ C_int 3; C_int 4 ])
let y = Sneaky1._subtract (C_list [ C_int 3; C_int 4 ])
let z = Sneaky1._mul (C_list [ C_int 3; C_int 4 ])
let w = Sneaky1._divide (C_list [ C_int 3; C_int 4 ])

View File

@@ -0,0 +1,28 @@
(* Throw exception test *)
open Swig
open Throw_exception
let x = new_Foo C_void ;;
let _ =
try
(invoke x) "test_int" C_void
with (Failure "Exception(37): Thrown exception from C++ (int)\n") ->
try
(invoke x) "test_msg" C_void
with (Failure "Exception(0): Dead\n") ->
try
(invoke x) "test_cls" C_void
with (Failure "Exception(0): Thrown exception from C++ (unknown)\n") ->
try
(invoke x) "test_multi" (C_int 1)
with (Failure "Exception(37): Thrown exception from C++ (int)\n") ->
try
(invoke x) "test_multi" (C_int 2)
with (Failure "Exception(0): Dead\n") ->
try
(invoke x) "test_multi" (C_int 3)
with (Failure "Exception(0): Thrown exception from C++ (unknown)\n") ->
exit 0
let _ = exit 1

View File

@@ -0,0 +1,16 @@
open Swig
open Typedef_mptr
let soci x = (string_of_int (get_int x))
let x = new_Foo C_void
let add_res = _do_op (C_list [ x ; C_int 2 ; C_int 1 ; _add ])
and sub_res = _do_op (C_list [ x ; C_int 2 ; C_int 1 ; _sub ])
let _ =
if add_res <> (C_int 3) || sub_res <> (C_int 1) then
raise (Failure ("Bad result:" ^
" (add " ^ (soci add_res) ^ ") " ^
" (sub " ^ (soci sub_res) ^ ")"))
let _ = Printf.printf "2 + 1 = %d, 2 - 1 = %d\n"
(get_int add_res)
(get_int sub_res)

View File

@@ -0,0 +1,12 @@
(* Fun with type names -- stolen from the ruby runme *)
open Swig
open Typename
let f = new_Foo C_void
let b = new_Bar C_void
let x = _twoFoo f
let _ = match x with C_double f -> () | _ -> raise (Failure "not a float")
let y = _twoBar b
let _ = match y with C_int i -> () | _ -> raise (Failure "not an int")

View File

@@ -0,0 +1,28 @@
(* Test the unions example... *)
open Swig
open Unions
let a = new_SmallStruct C_void
let b = new_BigStruct C_void
let c = new_UnionTest C_void
let d = new_EmbeddedUnionTest C_void
let _ = (invoke a) "jill" (C_short 3)
let _ = (invoke b) "jack" (C_char 'a') (* Int conversion *)
let _ = (invoke b) "smallstruct" a (* Put a in b *)
let _ = (invoke c) "bs" b
let _ = if get_int ((invoke a) "jill" C_void) != 3 then
raise (Failure "jill value is not preserved")
let _ = if get_int ((invoke b) "jack" C_void) != (int_of_char 'a') then
raise (Failure "jack value is not preserved")
let _ = if get_int ((invoke ((invoke b) "smallstruct" C_void))
"jill" C_void) != 3 then
raise (Failure "jill value is not embedded in bigstruct")
let _ = if get_int ((invoke ((invoke c) "bs" C_void))
"jack" C_void) != (int_of_char 'a') then
raise (Failure "union set of bigstruct did not take")
let _ = if get_int ((invoke ((invoke c) "ss" C_void))
"jill" C_void) != (int_of_char 'a') then
raise (Failure "corresponding union values are not the same")

View File

@@ -0,0 +1,8 @@
open Swig
open Using_protected
let f = new_FooBar C_void
let _ = (invoke f) "x" (C_int 3)
let _ = if (invoke f) "blah" (C_int 4) <> (C_int 4) then
raise (Failure "blah(int)")

View File

@@ -0,0 +1,11 @@
(* Test case stolen from the python directory *)
open Swig
open Varargs
let _ = if _test (C_string "Hello") <> (C_string "Hello") then
raise (Failure "1")
let f = new_Foo C_void
let _ = if (invoke f) "test" (C_string "Hello") <> (C_string "Hello") then
raise (Failure "2")

View File

@@ -0,0 +1,8 @@
open Swig
open Voidtest
let _ = _globalfunc C_void
let f = new_Foo C_void
let _ = (invoke f) "memberfunc" C_void
let _ = _Foo_staticmemberfunc C_void