From 74eb5b7dc324f7f185c1e229e81c294ee8bfb8e9 Mon Sep 17 00:00:00 2001 From: Marcelo Matus Date: Fri, 9 Apr 2004 21:56:14 +0000 Subject: [PATCH] add inplace test git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@5857 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- SWIG/Examples/test-suite/python/Makefile.in | 1 + SWIG/Examples/test-suite/python/inplaceadd.i | 31 +++++++++++++++++++ .../test-suite/python/inplaceadd_runme.py | 18 +++++++++++ 3 files changed, 50 insertions(+) create mode 100644 SWIG/Examples/test-suite/python/inplaceadd.i create mode 100644 SWIG/Examples/test-suite/python/inplaceadd_runme.py 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