diff --git a/SWIG/Examples/test-suite/python/Makefile.in b/SWIG/Examples/test-suite/python/Makefile.in index 594b7e904..6951f0f90 100644 --- a/SWIG/Examples/test-suite/python/Makefile.in +++ b/SWIG/Examples/test-suite/python/Makefile.in @@ -15,6 +15,7 @@ CPP_TEST_CASES += \ complextest \ director_stl \ implicittest \ + inplaceadd \ lib_std_vectora \ lib_std_map \ lib_std_wstring \ diff --git a/SWIG/Examples/test-suite/python/inplaceadd.i b/SWIG/Examples/test-suite/python/inplaceadd.i new file mode 100644 index 000000000..ab64119ba --- /dev/null +++ b/SWIG/Examples/test-suite/python/inplaceadd.i @@ -0,0 +1,31 @@ +%module inplaceadd + + +%inline %{ + struct A + { + int val; + + A(int v): val(v) + { + } + + A& operator+=(int v) + { + val += v; + return *this; + } + + A& operator-=(int v) + { + val -= v; + return *this; + } + + A& operator*=(int v) + { + val *= v; + return *this; + } + }; +%} diff --git a/SWIG/Examples/test-suite/python/inplaceadd_runme.py b/SWIG/Examples/test-suite/python/inplaceadd_runme.py new file mode 100644 index 000000000..743bb9203 --- /dev/null +++ b/SWIG/Examples/test-suite/python/inplaceadd_runme.py @@ -0,0 +1,18 @@ +import inplaceadd +a = inplaceadd.A(7) + +a += 5 +if a.val != 12: + raise RuntimeError + +if a.thisown != 1: + raise RuntimeError + +a -= 5 +if a.val != 7: + raise RuntimeError + +a *= 2 + +if a.val != 14: + raise RuntimeError