Merge remote-tracking branch 'upstream/master' into OCaml-INPUT-OUTPUT-INOUT-primitives
This commit is contained in:
commit
5a58f9a87b
25 changed files with 354 additions and 23 deletions
|
|
@ -1,13 +1,13 @@
|
|||
/* File : example.i */
|
||||
%module example
|
||||
|
||||
%typemap(argout) (int &x, int &y) {
|
||||
%typemap(argout) (const int &x, const int &y) {
|
||||
swig_result = caml_list_append(swig_result, caml_val_int(*$1));
|
||||
swig_result = caml_list_append(swig_result, caml_val_int(*$2));
|
||||
}
|
||||
|
||||
%{
|
||||
extern "C" void factor(int &x, int &y);
|
||||
extern "C" void factor(const int &x, const int &y);
|
||||
%}
|
||||
|
||||
extern "C" void factor(int &x, int &y);
|
||||
extern "C" void factor(const int &x, const int &y);
|
||||
|
|
|
|||
|
|
@ -647,6 +647,7 @@ CPP_STD_TEST_CASES += \
|
|||
li_std_pair_using \
|
||||
li_std_string \
|
||||
li_std_vector \
|
||||
li_std_vector_back_reference \
|
||||
li_std_vector_enum \
|
||||
li_std_vector_member_var\
|
||||
li_std_vector_ptr \
|
||||
|
|
|
|||
14
Examples/test-suite/li_std_vector_back_reference.i
Normal file
14
Examples/test-suite/li_std_vector_back_reference.i
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
%module li_std_vector_back_reference
|
||||
|
||||
%include <std_vector.i>
|
||||
|
||||
%inline %{
|
||||
// #include <iostream>
|
||||
struct Wheel {
|
||||
int size;
|
||||
Wheel(int sz = 0) : size(sz) {}
|
||||
// ~Wheel() { std::cout << "~Wheel" << std::endl; }
|
||||
};
|
||||
%}
|
||||
|
||||
%template(VectorWheel) std::vector<Wheel>;
|
||||
53
Examples/test-suite/ocaml/extend_placement_runme.ml
Normal file
53
Examples/test-suite/ocaml/extend_placement_runme.ml
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
open Swig
|
||||
open Extend_placement
|
||||
|
||||
let _ =
|
||||
let f = new_Foo '() in
|
||||
assert (f -> spam () as int = 1);
|
||||
assert (new_Foo '(1) -> spam () as int = 1);
|
||||
let f = new_Foo '(1, 1) in
|
||||
assert (f -> spam () as int = 1);
|
||||
assert (f -> spam ("hello") as int = 2);
|
||||
assert (f -> spam (1) as int = 1);
|
||||
assert (f -> spam (1, 2) as int = 3);
|
||||
assert (f -> spam (2, 4, 6) as int = 6);
|
||||
assert (f -> spam (f) as int = 0);
|
||||
let arg = C_double 1. in
|
||||
assert (f -> spam (f, arg) as int = 0);
|
||||
|
||||
assert (new_Bar '() -> spam () as int = 1);
|
||||
let b = new_Bar '(1) in
|
||||
assert (b -> spam () as int = 1);
|
||||
assert (b -> spam ("hello") as int = 2);
|
||||
assert (b -> spam (1) as int = 1);
|
||||
assert (b -> spam (1, 2) as int = 3);
|
||||
assert (b -> spam (2, 4, 6) as int = 6);
|
||||
assert (b -> spam (b) as int = 0);
|
||||
let arg = C_double 1. in
|
||||
assert (b -> spam (b, arg) as int = 0);
|
||||
|
||||
assert (new_FooTi '() -> spam () as int = 1);
|
||||
assert (new_FooTi '(1) -> spam () as int = 1);
|
||||
let f = new_FooTi '(1, 1) in
|
||||
assert (f -> spam () as int = 1);
|
||||
assert (f -> spam ("hello") as int = 2);
|
||||
assert (f -> spam (1) as int = 1);
|
||||
assert (f -> spam (1, 2) as int = 3);
|
||||
assert (f -> spam (2, 4, 6) as int = 6);
|
||||
let foo = new_Foo '() in
|
||||
assert (f -> spam (foo) as int = 0);
|
||||
let arg = C_double 1. in
|
||||
assert (f -> spam (foo, arg) as int = 0);
|
||||
|
||||
assert (new_BarTi '() -> spam () as int = 1);
|
||||
let b = new_BarTi '(1) in
|
||||
assert (b -> spam () as int = 1);
|
||||
assert (b -> spam ("hello") as int = 2);
|
||||
assert (b -> spam (1) as int = 1);
|
||||
assert (b -> spam (1, 2) as int = 3);
|
||||
assert (b -> spam (2, 4, 6) as int = 6);
|
||||
let bar = new_Bar '() in
|
||||
assert (b -> spam (bar) as int = 0);
|
||||
let arg = C_double 1. in
|
||||
assert (b -> spam (bar, arg) as int = 0);
|
||||
;;
|
||||
15
Examples/test-suite/ocaml/global_vars_runme.ml
Normal file
15
Examples/test-suite/ocaml/global_vars_runme.ml
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
open Swig
|
||||
open Global_vars
|
||||
|
||||
_init '()
|
||||
|
||||
let _ =
|
||||
assert (_b '() as string = "string b");
|
||||
assert (_b '("a string value") as string = "a string value");
|
||||
assert (_b '() as string = "a string value");
|
||||
assert (_x '() as int = 1234);
|
||||
assert (_x '(9876) as int = 9876);
|
||||
assert (_x '() as int = 9876);
|
||||
assert (_Hi '() as int = 0);
|
||||
assert (_Hola '() as int = 1);
|
||||
;;
|
||||
60
Examples/test-suite/ocaml/overload_template_runme.ml
Normal file
60
Examples/test-suite/ocaml/overload_template_runme.ml
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
open Swig
|
||||
open Overload_template
|
||||
|
||||
let _ =
|
||||
assert (_foo '() as int = 3);
|
||||
assert (_maximum '(3, 4) as int = 4);
|
||||
assert (_maximum '(3.4, 5.2) as float > 5.);
|
||||
assert (_mix1 '("hi") as int = 101);
|
||||
assert (_mix1 '(1.0, 1.0) as int = 102);
|
||||
assert (_mix1 '(1.0) as int = 103);
|
||||
assert (_mix2 '("hi") as int = 101);
|
||||
assert (_mix2 '(1.0, 1.0) as int = 102);
|
||||
assert (_mix2 '(1.0) as int = 103);
|
||||
assert (_mix3 '("hi") as int = 101);
|
||||
assert (_mix3 '(1.0, 1.0) as int = 102);
|
||||
assert (_mix3 '(1.0) as int = 103);
|
||||
|
||||
assert (_overtparams1 '(100) as int = 10);
|
||||
assert (_overtparams1 '(100.0, 100) as int = 20);
|
||||
assert (_overtparams2 '(100.0, 100) as int = 40);
|
||||
assert (_overloaded '() as int = 60);
|
||||
assert (_overloaded '(100.0, 100) as int = 70);
|
||||
assert (_overloadedagain '("hello") as int = 80);
|
||||
assert (_overloadedagain '() as int = 90);
|
||||
|
||||
assert (_specialization '(10) as int = 202);
|
||||
assert (_specialization '(10.0) as int = 203);
|
||||
assert (_specialization '(10, 10) as int = 204);
|
||||
assert (_specialization '(10.0, 10.0) as int = 205);
|
||||
assert (_specialization '("hi", "hi") as int = 201);
|
||||
|
||||
assert (_xyz '() = C_void);
|
||||
assert (_xyz_int '() = C_void);
|
||||
assert (_xyz_double '() = C_void);
|
||||
|
||||
assert (_overload '("hi") as int = 0);
|
||||
assert (_overload '(1) as int = 10);
|
||||
assert (_overload '(1, 1) as int = 20);
|
||||
assert (_overload '(1, "hello") as int = 30);
|
||||
let k = new_Klass '() in
|
||||
assert (_overload '(k) as int = 10);
|
||||
assert (_overload '(k, k) as int = 20);
|
||||
assert (_overload '(k, "hello") as int = 30);
|
||||
assert (_overload '(10.0, "hi") as int = 40);
|
||||
assert (_overload '() as int = 50);
|
||||
|
||||
assert (_nsoverload '("hi") as int = 1000);
|
||||
assert (_nsoverload '(1) as int = 1010);
|
||||
assert (_nsoverload '(1, 1) as int = 1020);
|
||||
assert (_nsoverload '(1, "hello") as int = 1030);
|
||||
assert (_nsoverload '(k) as int = 1010);
|
||||
assert (_nsoverload '(k, k) as int = 1020);
|
||||
assert (_nsoverload '(k, "hello") as int = 1030);
|
||||
assert (_nsoverload '(10.0, "hi") as int = 1040);
|
||||
assert (_nsoverload '() as int = 1050);
|
||||
|
||||
assert (_A_foo '(1) = C_void);
|
||||
let b = new_B '() in
|
||||
assert (b -> foo(1) = C_void);
|
||||
;;
|
||||
|
|
@ -22,7 +22,7 @@ let _ =
|
|||
|
||||
let _ = _var_short (_createref_short (C_short 10)) in
|
||||
assert (_value_short (_var_short '()) as int = 10);
|
||||
|
||||
|
||||
let _ = _var_unsigned_short (_createref_unsigned_short (C_ushort 10)) in
|
||||
assert (_value_unsigned_short (_var_unsigned_short '()) as int = 10);
|
||||
|
||||
|
|
|
|||
10
Examples/test-suite/ocaml/sizet_runme.ml
Normal file
10
Examples/test-suite/ocaml/sizet_runme.ml
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
open Swig
|
||||
open Sizet
|
||||
|
||||
let _ =
|
||||
let s = C_int64 2000L in
|
||||
assert (_test1 '(s) as int = 2000);
|
||||
assert (_test2 '(s) as int = 2000);
|
||||
assert (_test3 '(s) as int = 2000);
|
||||
assert (_test4 '(s) as int = 2000);
|
||||
;;
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
open Swig
|
||||
open Template_default_arg_overloaded_extend
|
||||
|
||||
let _ =
|
||||
let rs = new_ResultSet '() and sp = new_SearchPoint '() in
|
||||
assert (rs -> go_get_method (0, sp) as int = -1);
|
||||
assert (rs -> go_get_method (0, sp, 100) as int = 100);
|
||||
assert (rs -> go_get_template (0, sp) as int = -2);
|
||||
assert (rs -> go_get_template (0, sp, 100) as int = 100);
|
||||
|
||||
assert (rs -> over () as string = "over(int)");
|
||||
assert (rs -> over (10) as string = "over(int)");
|
||||
assert (rs -> over (sp) as string = "over(giai2::SearchPoint, int)");
|
||||
assert (rs -> over (sp, 10) as string = "over(giai2::SearchPoint, int)");
|
||||
assert (rs -> over (true, sp) as string = "over(bool, gaia2::SearchPoint, int)");
|
||||
assert (rs -> over (true, sp, 10) as string = "over(bool, gaia2::SearchPoint, int)");
|
||||
;;
|
||||
52
Examples/test-suite/ocaml/template_default_arg_runme.ml
Normal file
52
Examples/test-suite/ocaml/template_default_arg_runme.ml
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
open Swig
|
||||
open Template_default_arg
|
||||
|
||||
let _ =
|
||||
let helloInt = new_Hello_int '() and enumArg = _hi '() in
|
||||
assert (helloInt -> foo (enumArg) = C_void);
|
||||
assert (helloInt -> foo () = C_void);
|
||||
|
||||
let x = new_X_int '() in
|
||||
assert (x -> meth (20.0, 200) as int = 200);
|
||||
assert (x -> meth (20) as int = 20);
|
||||
assert (x -> meth () as int = 0);
|
||||
|
||||
let x = new_Y_unsigned '() in
|
||||
let args = C_list [ C_double 20.0 ; C_uint 200l ] in
|
||||
assert (x -> meth (args) as int = 200);
|
||||
let args = C_uint 20l in
|
||||
assert (x -> meth (args) as int = 20);
|
||||
assert (x -> meth () as int = 0);
|
||||
|
||||
let x = new_X_longlong '() in
|
||||
assert (x -> meth (20.0) as int = 0);
|
||||
let x = new_X_longlong '(20.0) in
|
||||
assert (x -> meth (20.0) as int = 0);
|
||||
let args = C_list [ C_double 20.0 ; C_int64 200L ] in
|
||||
let x = new_X_longlong '(args) in
|
||||
assert (x -> meth (20.0) as int = 0);
|
||||
|
||||
let x = new_X_int '() in
|
||||
assert (x -> meth (20.0) as int = 0);
|
||||
let x = new_X_int '(20.0) in
|
||||
assert (x -> meth (20.0) as int = 0);
|
||||
let x = new_X_int '(20.0, 200) in
|
||||
assert (x -> meth (20.0) as int = 0);
|
||||
|
||||
let arg = new_Foo_int '() in
|
||||
assert (_ott '(arg) as int = 30);
|
||||
assert (_ott '() as int = 10);
|
||||
assert (_ott '(1) as int = 10);
|
||||
assert (_ott '(1, 1) as int = 10);
|
||||
assert (_ott '("hi") as int = 20);
|
||||
assert (_ott '("hi", 1) as int = 20);
|
||||
assert (_ott '("hi", 1, 1) as int = 20);
|
||||
|
||||
let arg = new_Hello_int '() in
|
||||
assert (_ottstring '(arg, "hi") as int = 40);
|
||||
assert (_ottstring '(arg) as int = 40);
|
||||
assert (_ottint '(arg, 1) as int = 50);
|
||||
assert (_ottint '(arg) as int = 50);
|
||||
assert (_ott '(arg, 1.0) as int = 60);
|
||||
assert (_ott '(arg) as int = 60);
|
||||
;;
|
||||
11
Examples/test-suite/ocaml/typedef_reference_runme.ml
Normal file
11
Examples/test-suite/ocaml/typedef_reference_runme.ml
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
open Swig
|
||||
open Typedef_reference
|
||||
|
||||
let _ =
|
||||
let i = _copy_intp '(2) in
|
||||
assert (_somefunc '(i) as int = 2);
|
||||
assert (_delete_intp '(i) = C_void);
|
||||
let i = _copy_intp '(3) in
|
||||
assert (_otherfunc '(i) as int = 3);
|
||||
assert (_delete_intp '(i) = C_void);
|
||||
;;
|
||||
10
Examples/test-suite/ocaml/wrapmacro_runme.ml
Normal file
10
Examples/test-suite/ocaml/wrapmacro_runme.ml
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
open Swig
|
||||
open Wrapmacro
|
||||
|
||||
let _ =
|
||||
let args = C_list [ C_int64 2L ; C_int64 1L ] in
|
||||
assert (_maximum '(args) as int = 2);
|
||||
let args = C_list [ C_double (2. /. 7.) ; C_double 256. ] in
|
||||
assert (_maximum '(args) as float = 256.);
|
||||
assert (_GUINT16_SWAP_LE_BE_CONSTANT '(0x1234) as int = 0x3412);
|
||||
;;
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
from li_std_vector_back_reference import *
|
||||
|
||||
def first_element():
|
||||
v = VectorWheel((Wheel(11), Wheel(22)))
|
||||
# v will be deleted after exit from this method
|
||||
return v[0]
|
||||
|
||||
size = first_element().size
|
||||
if size != 11:
|
||||
raise RuntimeError("Back reference not working {}".format(size))
|
||||
Loading…
Add table
Add a link
Reference in a new issue