From 27f964987ac68c72453ca189831287511f07a5be Mon Sep 17 00:00:00 2001 From: Zackery Spytz Date: Fri, 21 Apr 2023 09:38:15 +1200 Subject: [OCaml] Fix reference typemaps for std::string Fix warnings in the extend_template_method, li_std_string, and template_methods tests. std::string was missing a typecheck typemap. Add extend_template_method_runme.ml, li_std_string_runme.ml, and template_methods_runme.ml. Add INPUT, OUTPUT and INOUT typemaps for string & Use the INOUT typemap in the strings_test example. In the strings_test example, takes_and_gives_std_string() was relying on the silly fact that an argout typemap for string & was enabled by default. Remove the in, out, and typecheck typemaps for string &. Closes: #1439 --- Examples/ocaml/strings_test/example.i | 1 + .../ocaml/extend_template_method_runme.ml | 20 ++++++++++ Examples/test-suite/ocaml/li_std_string_runme.ml | 44 ++++++++++++++++++++++ .../test-suite/ocaml/template_methods_runme.ml | 25 ++++++++++++ 4 files changed, 90 insertions(+) create mode 100644 Examples/test-suite/ocaml/extend_template_method_runme.ml create mode 100644 Examples/test-suite/ocaml/li_std_string_runme.ml create mode 100644 Examples/test-suite/ocaml/template_methods_runme.ml (limited to 'Examples') diff --git a/Examples/ocaml/strings_test/example.i b/Examples/ocaml/strings_test/example.i index d360715c1..e0697b061 100644 --- a/Examples/ocaml/strings_test/example.i +++ b/Examples/ocaml/strings_test/example.i @@ -12,4 +12,5 @@ using std::string; %} %include "std_string.i" +%apply std::string& INOUT { std::string &inout } %include example.h diff --git a/Examples/test-suite/ocaml/extend_template_method_runme.ml b/Examples/test-suite/ocaml/extend_template_method_runme.ml new file mode 100644 index 000000000..5f418c927 --- /dev/null +++ b/Examples/test-suite/ocaml/extend_template_method_runme.ml @@ -0,0 +1,20 @@ +open Swig +open Extend_template_method + +let _ = + let em = new_ExtendMe '() in + assert (em -> do_stuff_double (1, 1.1) as float = 1.1); + assert (em -> do_stuff_string (1, "hello there") as string = "hello there"); + assert (em -> do_overloaded_stuff (1.1) as float = 1.1); + assert (em -> do_overloaded_stuff ("hello there") as string = "hello there"); + + assert (_ExtendMe_static_method '(123) as int = 123); + ignore (new_ExtendMe '(123)); + let em = new_TemplateExtend '() in + assert (em -> do_template_stuff_double (1, 1.1) as float = 1.1); + assert (em -> do_template_stuff_string (1, "hello there") as string = "hello there"); + assert (em -> do_template_overloaded_stuff (1.1) as float = 1.1); + assert (em -> do_template_overloaded_stuff ("hello there") as string = "hello there"); + assert (_TemplateExtend_static_template_method '(123) as int = 123); + ignore (new_TemplateExtend '(123)) +;; diff --git a/Examples/test-suite/ocaml/li_std_string_runme.ml b/Examples/test-suite/ocaml/li_std_string_runme.ml new file mode 100644 index 000000000..5f8c98a6b --- /dev/null +++ b/Examples/test-suite/ocaml/li_std_string_runme.ml @@ -0,0 +1,44 @@ +open Swig +open Li_std_string + +let _ = + assert (_test_value '("Fee") as string = "Fee"); + try + ignore (_test_value '(None)); assert false + with Invalid_argument _ -> () + + assert (_test_const_reference '("Fee") as string = "Fee"); + try + ignore (_test_const_reference '(None)); assert false + with Invalid_argument _ -> () + + let stringPtr = _test_pointer_out '() in + ignore (_test_pointer '(stringPtr)); + let stringPtr = _test_const_pointer_out '() in + ignore (_test_const_pointer '(stringPtr)); + let stringPtr = _test_reference_out '() in + ignore (_test_reference '(stringPtr)); + + try + ignore (_test_throw '()); assert false + with Failure s -> assert (s = "test_throw message") + try + ignore (_test_const_reference_throw '()); assert false + with Failure s -> assert (s = "test_const_reference_throw message") + assert (_GlobalString2 '() as string = "global string 2"); + let s = C_string "initial string" in + ignore (_GlobalString2 '(s)); + assert (_GlobalString2 '() = s); + assert (_ConstGlobalString '() as string = "const global string"); + + let myStructure = new_Structure '() in + assert (myStructure -> "[MemberString2]" () as string = "member string 2"); + assert (myStructure -> "[MemberString2]" (s) = C_void); + assert (myStructure -> "[MemberString2]" () = s); + assert (myStructure -> "[ConstMemberString]" () as string = "const member string"); + + assert (_Structure_StaticMemberString2 '() as string = "static member string 2"); + ignore (_Structure_StaticMemberString2 '(s)); + assert (_Structure_StaticMemberString2 '() = s); + assert (_Structure_ConstStaticMemberString '() as string = "const static member string") +;; diff --git a/Examples/test-suite/ocaml/template_methods_runme.ml b/Examples/test-suite/ocaml/template_methods_runme.ml new file mode 100644 index 000000000..aaa5a3416 --- /dev/null +++ b/Examples/test-suite/ocaml/template_methods_runme.ml @@ -0,0 +1,25 @@ +open Swig +open Template_methods + +let _ = + let num = C_float 1. in + assert (_convolve1Bool '() as int = 0); + assert (_convolve1Bool '(true) = C_void); + assert (_convolve2Float '() as int = 0); + assert (_convolve3FloatRenamed '(num) = C_void); + assert (_convolve4Float '() as int = 0); + assert (_convolve4FloatRenamed '(num) = C_void); + assert (_convolve5FloatRenamed '() as int = 0); + assert (_convolve5FloatRenamed '(num) = C_void); + + let k = new_Klass '() in + assert (k -> KlassTMethodBoolRenamed (true) as bool = true); + assert (k -> KlassTMethodBool () = C_void); + assert (_Klass_KlassStaticTMethodBoolRenamed '(true) as bool = true); + assert (_Klass_KlassStaticTMethodBool '() = C_void); + + let cp = new_ComponentProperties '() in + assert (cp -> adda ("key1", "val1", "key2", 22.2) = C_void); + assert (cp -> adda ("key1", "val1", "key2", "val2", "key3", "val3") = C_void); + assert (cp -> adda ("key1", 1, "key2", 2, "key3", 3) = C_void) +;; -- cgit v1.2.1