mirror of https://github.com/swig/swig
Expand std::shared_ptr testing to C# D Java Python
This commit is contained in:
parent
9e79d3566b
commit
f5e1856650
|
@ -7,10 +7,10 @@
|
||||||
|
|
||||||
class Foo
|
class Foo
|
||||||
{
|
{
|
||||||
|
int m;
|
||||||
public:
|
public:
|
||||||
Foo(int i) : m(i) {}
|
Foo(int i) : m(i) {}
|
||||||
int get_m() { return m;}
|
int get_m() { return m;}
|
||||||
int m;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
std::shared_ptr<Foo> foo(Foo v) {
|
std::shared_ptr<Foo> foo(Foo v) {
|
||||||
|
@ -45,10 +45,10 @@ std::vector<std::shared_ptr<const Foo> > const_foo_vec(Foo v) {
|
||||||
|
|
||||||
class Foo
|
class Foo
|
||||||
{
|
{
|
||||||
|
int m;
|
||||||
public:
|
public:
|
||||||
Foo(int i);
|
Foo(int i);
|
||||||
int get_m();
|
int get_m();
|
||||||
int m;
|
|
||||||
};
|
};
|
||||||
std::shared_ptr<Foo> foo(Foo v);
|
std::shared_ptr<Foo> foo(Foo v);
|
||||||
std::shared_ptr<const Foo> const_foo(Foo v);
|
std::shared_ptr<const Foo> const_foo(Foo v);
|
||||||
|
|
|
@ -15,11 +15,11 @@ class C;
|
||||||
%inline %{
|
%inline %{
|
||||||
|
|
||||||
class C {
|
class C {
|
||||||
|
int m;
|
||||||
public:
|
public:
|
||||||
C() : m(-1) {}
|
C() : m(-1) {}
|
||||||
C(int i) : m(i) {}
|
C(int i) : m(i) {}
|
||||||
int get_m() { return m; }
|
int get_m() { return m; }
|
||||||
int m;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
%}
|
%}
|
||||||
|
|
|
@ -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 <std_string.i>
|
||||||
|
%include <std_shared_ptr.i>
|
||||||
|
|
||||||
|
%warnfilter(SWIGWARN_LANG_OVERLOAD_IGNORED,SWIGWARN_LANG_OVERLOAD_SHADOW) UseA(std::shared_ptr<MyType> mytype);
|
||||||
|
%warnfilter(SWIGWARN_LANG_OVERLOAD_IGNORED,SWIGWARN_LANG_OVERLOAD_SHADOW) UseB(int, std::shared_ptr<MyType> mytype);
|
||||||
|
%warnfilter(SWIGWARN_LANG_OVERLOAD_IGNORED,SWIGWARN_LANG_OVERLOAD_SHADOW) UseC(int, std::shared_ptr<MyType> mytype, std::shared_ptr<MyType>);
|
||||||
|
|
||||||
|
%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<MyType>);
|
||||||
|
|
||||||
|
%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 <memory>
|
||||||
|
#include <string>
|
||||||
|
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> mytype) { return mytype->val + " sharedptr"; }
|
||||||
|
|
||||||
|
std::string UseB(int, MyType &mytype) { return mytype.val + " ref"; }
|
||||||
|
std::string UseB(int, std::shared_ptr<MyType> mytype) { return mytype->val + " sharedptr"; }
|
||||||
|
|
||||||
|
std::string UseC(int, MyType &mytype, std::shared_ptr<MyType>) { return mytype.val + " ref"; }
|
||||||
|
std::string UseC(int, std::shared_ptr<MyType> mytype, std::shared_ptr<MyType>) { return mytype->val + " sharedptr"; }
|
||||||
|
|
||||||
|
// sharedptr
|
||||||
|
std::string UseX(std::shared_ptr<MyType> mytype) { return mytype->val + " sharedptr"; }
|
||||||
|
std::string UseX(MyType &mytype) { return mytype.val + " ref"; }
|
||||||
|
|
||||||
|
std::string UseY(int, std::shared_ptr<MyType> mytype) { return mytype->val + " sharedptr"; }
|
||||||
|
std::string UseY(int, MyType &mytype) { return mytype.val + " ref"; }
|
||||||
|
|
||||||
|
std::string UseZ(int, std::shared_ptr<MyType> mytype, std::shared_ptr<MyType>) { return mytype->val + " sharedptr"; }
|
||||||
|
std::string UseZ(int, MyType &mytype, std::shared_ptr<MyType>) { 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> mytype) { return ""; }
|
||||||
|
std::string Combo1(std::shared_ptr<MyType>* mytype) { return ""; }
|
||||||
|
|
||||||
|
std::string Combo2(MyType *mytype) { return mytype->val + "Combo2"; }
|
||||||
|
std::string Combo2(std::shared_ptr<MyType> mytype) { return ""; }
|
||||||
|
std::string Combo2(std::shared_ptr<MyType>* mytype) { return ""; }
|
||||||
|
std::string Combo2(MyType mytype) { return ""; }
|
||||||
|
|
||||||
|
std::string Combo3(std::shared_ptr<MyType> mytype) { return mytype->val + "Combo3"; }
|
||||||
|
std::string Combo3(std::shared_ptr<MyType>* mytype) { return ""; }
|
||||||
|
std::string Combo3(MyType mytype) { return ""; }
|
||||||
|
std::string Combo3(MyType *mytype) { return ""; }
|
||||||
|
|
||||||
|
std::string Combo4(std::shared_ptr<MyType>* mytype) { return (*mytype)->val + "Combo4"; }
|
||||||
|
std::string Combo4(MyType mytype) { return ""; }
|
||||||
|
std::string Combo4(MyType *mytype) { return ""; }
|
||||||
|
std::string Combo4(std::shared_ptr<MyType> 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> mytype) { return ""; }
|
||||||
|
|
||||||
|
std::string Combo6(MyType *mytype) { return mytype->val + "Combo6"; }
|
||||||
|
std::string Combo6(std::shared_ptr<MyType> mytype) { return ""; }
|
||||||
|
std::string Combo6(MyType &mytype) { return ""; }
|
||||||
|
|
||||||
|
std::string Combo7(std::shared_ptr<MyType> mytype) { return mytype->val + "Combo7"; }
|
||||||
|
std::string Combo7(MyType &mytype) { return ""; }
|
||||||
|
std::string Combo7(MyType *mytype) { return ""; }
|
||||||
|
%}
|
|
@ -16,19 +16,19 @@
|
||||||
%{
|
%{
|
||||||
|
|
||||||
class Base {
|
class Base {
|
||||||
|
int m;
|
||||||
public:
|
public:
|
||||||
Base() : m(-1) {}
|
Base() : m(-1) {}
|
||||||
Base(int i) : m(i) {}
|
Base(int i) : m(i) {}
|
||||||
int get_m() { return m; }
|
int get_m() { return m; }
|
||||||
int m;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class Derived : public Base {
|
class Derived : public Base {
|
||||||
|
int n;
|
||||||
public:
|
public:
|
||||||
Derived() : n(-2) {}
|
Derived() : n(-2) {}
|
||||||
Derived(int i) : n(i) {}
|
Derived(int i) : n(i) {}
|
||||||
int get_n() { return n; }
|
int get_n() { return n; }
|
||||||
int n;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef std::shared_ptr<Base> BasePtr;
|
typedef std::shared_ptr<Base> BasePtr;
|
||||||
|
@ -96,18 +96,18 @@ int base_num(std::map<int, BasePtr > v) {
|
||||||
%template(DerivedMap) std::map<int, std::shared_ptr<Derived> >;
|
%template(DerivedMap) std::map<int, std::shared_ptr<Derived> >;
|
||||||
|
|
||||||
class Base {
|
class Base {
|
||||||
|
int m;
|
||||||
public:
|
public:
|
||||||
Base();
|
Base();
|
||||||
int get_m();
|
int get_m();
|
||||||
int m;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class Derived : public Base {
|
class Derived : public Base {
|
||||||
|
int n;
|
||||||
public:
|
public:
|
||||||
Derived();
|
Derived();
|
||||||
Derived(int i);
|
Derived(int i);
|
||||||
int get_n();
|
int get_n();
|
||||||
int n;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef std::shared_ptr<Base> BasePtr;
|
typedef std::shared_ptr<Base> BasePtr;
|
||||||
|
@ -135,20 +135,20 @@ int base_num(std::map<int, BasePtr > v);
|
||||||
|
|
||||||
%inline %{
|
%inline %{
|
||||||
class Base2 {
|
class Base2 {
|
||||||
|
int m;
|
||||||
public:
|
public:
|
||||||
Base2() : m(-1) {}
|
Base2() : m(-1) {}
|
||||||
Base2(int i) : m(i) {}
|
Base2(int i) : m(i) {}
|
||||||
int get_m() { return m; }
|
int get_m() { return m; }
|
||||||
int m;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
class Derived2 : public Base2 {
|
class Derived2 : public Base2 {
|
||||||
|
int n;
|
||||||
public:
|
public:
|
||||||
Derived2() : n(0) {}
|
Derived2() : n(0) {}
|
||||||
Derived2(int i) : n(i) {}
|
Derived2(int i) : n(i) {}
|
||||||
int get_n_2() { return n; }
|
int get_n_2() { return n; }
|
||||||
int n;
|
|
||||||
};
|
};
|
||||||
%}
|
%}
|
||||||
|
|
||||||
|
|
|
@ -29,6 +29,9 @@ CPP_TEST_CASES = \
|
||||||
li_boost_intrusive_ptr
|
li_boost_intrusive_ptr
|
||||||
|
|
||||||
CPP11_TEST_CASES = \
|
CPP11_TEST_CASES = \
|
||||||
|
cpp11_shared_ptr_const \
|
||||||
|
cpp11_shared_ptr_nullptr_in_containers \
|
||||||
|
cpp11_shared_ptr_upcast \
|
||||||
cpp11_strongly_typed_enumerations_simple \
|
cpp11_strongly_typed_enumerations_simple \
|
||||||
|
|
||||||
include $(srcdir)/../common.mk
|
include $(srcdir)/../common.mk
|
||||||
|
|
|
@ -24,6 +24,11 @@ CPP_TEST_CASES = \
|
||||||
d_nativepointers \
|
d_nativepointers \
|
||||||
exception_partial_info
|
exception_partial_info
|
||||||
|
|
||||||
|
CPP11_TEST_CASES = \
|
||||||
|
cpp11_shared_ptr_const \
|
||||||
|
cpp11_shared_ptr_nullptr_in_containers \
|
||||||
|
cpp11_shared_ptr_upcast \
|
||||||
|
|
||||||
include $(srcdir)/../common.mk
|
include $(srcdir)/../common.mk
|
||||||
|
|
||||||
# Overridden variables here
|
# Overridden variables here
|
||||||
|
|
|
@ -44,6 +44,9 @@ CPP_TEST_CASES = \
|
||||||
# li_boost_intrusive_ptr
|
# li_boost_intrusive_ptr
|
||||||
|
|
||||||
CPP11_TEST_CASES = \
|
CPP11_TEST_CASES = \
|
||||||
|
cpp11_shared_ptr_const \
|
||||||
|
cpp11_shared_ptr_nullptr_in_containers \
|
||||||
|
cpp11_shared_ptr_upcast \
|
||||||
cpp11_strongly_typed_enumerations_simple \
|
cpp11_strongly_typed_enumerations_simple \
|
||||||
|
|
||||||
include $(srcdir)/../common.mk
|
include $(srcdir)/../common.mk
|
||||||
|
|
|
@ -81,6 +81,9 @@ CPP_TEST_CASES += \
|
||||||
|
|
||||||
CPP11_TEST_CASES = \
|
CPP11_TEST_CASES = \
|
||||||
cpp11_hash_tables \
|
cpp11_hash_tables \
|
||||||
|
cpp11_shared_ptr_const \
|
||||||
|
cpp11_shared_ptr_nullptr_in_containers \
|
||||||
|
cpp11_shared_ptr_upcast \
|
||||||
|
|
||||||
C_TEST_CASES += \
|
C_TEST_CASES += \
|
||||||
file_test \
|
file_test \
|
||||||
|
|
Loading…
Reference in New Issue