From f5e18566507133b6d4ed03035dbca9ee3c1553c7 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Fri, 22 Sep 2017 20:03:47 +0100 Subject: [PATCH] Expand std::shared_ptr testing to C# D Java Python --- Examples/test-suite/cpp11_shared_ptr_const.i | 4 +- .../cpp11_shared_ptr_nullptr_in_containers.i | 2 +- .../test-suite/cpp11_shared_ptr_overload.i | 89 +++++++++++++++++++ Examples/test-suite/cpp11_shared_ptr_upcast.i | 12 +-- Examples/test-suite/csharp/Makefile.in | 3 + Examples/test-suite/d/Makefile.in | 5 ++ Examples/test-suite/java/Makefile.in | 3 + Examples/test-suite/python/Makefile.in | 3 + 8 files changed, 112 insertions(+), 9 deletions(-) create mode 100644 Examples/test-suite/cpp11_shared_ptr_overload.i diff --git a/Examples/test-suite/cpp11_shared_ptr_const.i b/Examples/test-suite/cpp11_shared_ptr_const.i index 0d1acdac0..5e38123b4 100644 --- a/Examples/test-suite/cpp11_shared_ptr_const.i +++ b/Examples/test-suite/cpp11_shared_ptr_const.i @@ -7,10 +7,10 @@ class Foo { + int m; public: Foo(int i) : m(i) {} int get_m() { return m;} - int m; }; std::shared_ptr foo(Foo v) { @@ -45,10 +45,10 @@ std::vector > const_foo_vec(Foo v) { class Foo { + int m; public: Foo(int i); int get_m(); - int m; }; std::shared_ptr foo(Foo v); std::shared_ptr const_foo(Foo v); diff --git a/Examples/test-suite/cpp11_shared_ptr_nullptr_in_containers.i b/Examples/test-suite/cpp11_shared_ptr_nullptr_in_containers.i index 46e2501d7..2167dfb73 100644 --- a/Examples/test-suite/cpp11_shared_ptr_nullptr_in_containers.i +++ b/Examples/test-suite/cpp11_shared_ptr_nullptr_in_containers.i @@ -15,11 +15,11 @@ class C; %inline %{ class C { + int m; public: C() : m(-1) {} C(int i) : m(i) {} int get_m() { return m; } - int m; }; %} diff --git a/Examples/test-suite/cpp11_shared_ptr_overload.i b/Examples/test-suite/cpp11_shared_ptr_overload.i new file mode 100644 index 000000000..ab84fda9a --- /dev/null +++ b/Examples/test-suite/cpp11_shared_ptr_overload.i @@ -0,0 +1,89 @@ +%module cpp11_shared_ptr_overload + +// Tests to ensure valid overloading in C++ between shared_ptr and other types result in code that compiles +// and all but the 1st overloaded method are automatically ignored/shadowed. +// Tests the 'equivalent' attribute in the 'typecheck' typemap. + +%include +%include + +%warnfilter(SWIGWARN_LANG_OVERLOAD_IGNORED,SWIGWARN_LANG_OVERLOAD_SHADOW) UseA(std::shared_ptr mytype); +%warnfilter(SWIGWARN_LANG_OVERLOAD_IGNORED,SWIGWARN_LANG_OVERLOAD_SHADOW) UseB(int, std::shared_ptr mytype); +%warnfilter(SWIGWARN_LANG_OVERLOAD_IGNORED,SWIGWARN_LANG_OVERLOAD_SHADOW) UseC(int, std::shared_ptr mytype, std::shared_ptr); + +%warnfilter(SWIGWARN_LANG_OVERLOAD_IGNORED,SWIGWARN_LANG_OVERLOAD_SHADOW) UseX(MyType &mytype); +%warnfilter(SWIGWARN_LANG_OVERLOAD_IGNORED,SWIGWARN_LANG_OVERLOAD_SHADOW) UseY(int, MyType &mytype); +%warnfilter(SWIGWARN_LANG_OVERLOAD_IGNORED,SWIGWARN_LANG_OVERLOAD_SHADOW) UseZ(int, MyType &mytype, std::shared_ptr); + +%warnfilter(SWIGWARN_LANG_OVERLOAD_IGNORED,SWIGWARN_LANG_OVERLOAD_SHADOW) Combo1; +%warnfilter(SWIGWARN_LANG_OVERLOAD_IGNORED,SWIGWARN_LANG_OVERLOAD_SHADOW) Combo2; +%warnfilter(SWIGWARN_LANG_OVERLOAD_IGNORED,SWIGWARN_LANG_OVERLOAD_SHADOW) Combo3; +%warnfilter(SWIGWARN_LANG_OVERLOAD_IGNORED,SWIGWARN_LANG_OVERLOAD_SHADOW) Combo4; +%warnfilter(SWIGWARN_LANG_OVERLOAD_IGNORED,SWIGWARN_LANG_OVERLOAD_SHADOW) Combo5; +%warnfilter(SWIGWARN_LANG_OVERLOAD_IGNORED,SWIGWARN_LANG_OVERLOAD_SHADOW) Combo6; +%warnfilter(SWIGWARN_LANG_OVERLOAD_IGNORED,SWIGWARN_LANG_OVERLOAD_SHADOW) Combo7; + +%shared_ptr(MyType); + +%inline %{ +#include +#include +struct MyType { + std::string val; + MyType(std::string val = std::string()) : val(val) {} +}; + +// ref +std::string UseA(MyType &mytype) { return mytype.val + " ref"; } +std::string UseA(std::shared_ptr mytype) { return mytype->val + " sharedptr"; } + +std::string UseB(int, MyType &mytype) { return mytype.val + " ref"; } +std::string UseB(int, std::shared_ptr mytype) { return mytype->val + " sharedptr"; } + +std::string UseC(int, MyType &mytype, std::shared_ptr) { return mytype.val + " ref"; } +std::string UseC(int, std::shared_ptr mytype, std::shared_ptr) { return mytype->val + " sharedptr"; } + +// sharedptr +std::string UseX(std::shared_ptr mytype) { return mytype->val + " sharedptr"; } +std::string UseX(MyType &mytype) { return mytype.val + " ref"; } + +std::string UseY(int, std::shared_ptr mytype) { return mytype->val + " sharedptr"; } +std::string UseY(int, MyType &mytype) { return mytype.val + " ref"; } + +std::string UseZ(int, std::shared_ptr mytype, std::shared_ptr) { return mytype->val + " sharedptr"; } +std::string UseZ(int, MyType &mytype, std::shared_ptr) { return mytype.val + " ref"; } + +// Combo1-4 +std::string Combo1(MyType mytype) { return mytype.val + "Combo1"; } +std::string Combo1(MyType *mytype) { return ""; } +std::string Combo1(std::shared_ptr mytype) { return ""; } +std::string Combo1(std::shared_ptr* mytype) { return ""; } + +std::string Combo2(MyType *mytype) { return mytype->val + "Combo2"; } +std::string Combo2(std::shared_ptr mytype) { return ""; } +std::string Combo2(std::shared_ptr* mytype) { return ""; } +std::string Combo2(MyType mytype) { return ""; } + +std::string Combo3(std::shared_ptr mytype) { return mytype->val + "Combo3"; } +std::string Combo3(std::shared_ptr* mytype) { return ""; } +std::string Combo3(MyType mytype) { return ""; } +std::string Combo3(MyType *mytype) { return ""; } + +std::string Combo4(std::shared_ptr* mytype) { return (*mytype)->val + "Combo4"; } +std::string Combo4(MyType mytype) { return ""; } +std::string Combo4(MyType *mytype) { return ""; } +std::string Combo4(std::shared_ptr mytype) { return ""; } + +// Combo5-7 +std::string Combo5(MyType &mytype) { return mytype.val + "Combo5"; } +std::string Combo5(MyType *mytype) { return ""; } +std::string Combo5(std::shared_ptr mytype) { return ""; } + +std::string Combo6(MyType *mytype) { return mytype->val + "Combo6"; } +std::string Combo6(std::shared_ptr mytype) { return ""; } +std::string Combo6(MyType &mytype) { return ""; } + +std::string Combo7(std::shared_ptr mytype) { return mytype->val + "Combo7"; } +std::string Combo7(MyType &mytype) { return ""; } +std::string Combo7(MyType *mytype) { return ""; } +%} diff --git a/Examples/test-suite/cpp11_shared_ptr_upcast.i b/Examples/test-suite/cpp11_shared_ptr_upcast.i index 3427829d9..9d85f43d4 100644 --- a/Examples/test-suite/cpp11_shared_ptr_upcast.i +++ b/Examples/test-suite/cpp11_shared_ptr_upcast.i @@ -16,19 +16,19 @@ %{ class Base { + int m; public: Base() : m(-1) {} Base(int i) : m(i) {} int get_m() { return m; } - int m; }; class Derived : public Base { + int n; public: Derived() : n(-2) {} Derived(int i) : n(i) {} int get_n() { return n; } - int n; }; typedef std::shared_ptr BasePtr; @@ -96,18 +96,18 @@ int base_num(std::map v) { %template(DerivedMap) std::map >; class Base { + int m; public: Base(); int get_m(); - int m; }; class Derived : public Base { + int n; public: Derived(); Derived(int i); int get_n(); - int n; }; typedef std::shared_ptr BasePtr; @@ -135,20 +135,20 @@ int base_num(std::map v); %inline %{ class Base2 { + int m; public: Base2() : m(-1) {} Base2(int i) : m(i) {} int get_m() { return m; } - int m; }; class Derived2 : public Base2 { + int n; public: Derived2() : n(0) {} Derived2(int i) : n(i) {} int get_n_2() { return n; } - int n; }; %} diff --git a/Examples/test-suite/csharp/Makefile.in b/Examples/test-suite/csharp/Makefile.in index 292854a9f..a59399af3 100644 --- a/Examples/test-suite/csharp/Makefile.in +++ b/Examples/test-suite/csharp/Makefile.in @@ -29,6 +29,9 @@ CPP_TEST_CASES = \ li_boost_intrusive_ptr CPP11_TEST_CASES = \ + cpp11_shared_ptr_const \ + cpp11_shared_ptr_nullptr_in_containers \ + cpp11_shared_ptr_upcast \ cpp11_strongly_typed_enumerations_simple \ include $(srcdir)/../common.mk diff --git a/Examples/test-suite/d/Makefile.in b/Examples/test-suite/d/Makefile.in index 3333df110..75c93ed7a 100644 --- a/Examples/test-suite/d/Makefile.in +++ b/Examples/test-suite/d/Makefile.in @@ -24,6 +24,11 @@ CPP_TEST_CASES = \ d_nativepointers \ exception_partial_info +CPP11_TEST_CASES = \ + cpp11_shared_ptr_const \ + cpp11_shared_ptr_nullptr_in_containers \ + cpp11_shared_ptr_upcast \ + include $(srcdir)/../common.mk # Overridden variables here diff --git a/Examples/test-suite/java/Makefile.in b/Examples/test-suite/java/Makefile.in index 503631217..0f8fd9767 100644 --- a/Examples/test-suite/java/Makefile.in +++ b/Examples/test-suite/java/Makefile.in @@ -44,6 +44,9 @@ CPP_TEST_CASES = \ # li_boost_intrusive_ptr CPP11_TEST_CASES = \ + cpp11_shared_ptr_const \ + cpp11_shared_ptr_nullptr_in_containers \ + cpp11_shared_ptr_upcast \ cpp11_strongly_typed_enumerations_simple \ include $(srcdir)/../common.mk diff --git a/Examples/test-suite/python/Makefile.in b/Examples/test-suite/python/Makefile.in index 6db0b2b7c..ce9dbad13 100644 --- a/Examples/test-suite/python/Makefile.in +++ b/Examples/test-suite/python/Makefile.in @@ -81,6 +81,9 @@ CPP_TEST_CASES += \ CPP11_TEST_CASES = \ cpp11_hash_tables \ + cpp11_shared_ptr_const \ + cpp11_shared_ptr_nullptr_in_containers \ + cpp11_shared_ptr_upcast \ C_TEST_CASES += \ file_test \