From ba575159f6ae78a5353bd1408fed843ea8089e98 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sat, 8 Dec 2012 10:37:04 +0000 Subject: Add runtime test for %implicitconv git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13950 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Examples/test-suite/implicittest.i | 3 +- Examples/test-suite/python/implicittest_runme.py | 73 ++++++++++++++++++++++++ 2 files changed, 74 insertions(+), 2 deletions(-) create mode 100644 Examples/test-suite/python/implicittest_runme.py (limited to 'Examples/test-suite') diff --git a/Examples/test-suite/implicittest.i b/Examples/test-suite/implicittest.i index 91205aafa..e07adc5cc 100644 --- a/Examples/test-suite/implicittest.i +++ b/Examples/test-suite/implicittest.i @@ -18,7 +18,6 @@ explicit A(char *s) { ii = 4; } int get() const { return ii; } - }; int get(const A& a) { return a.ii; } @@ -33,7 +32,7 @@ explicit A_T(char *s) { ii = 4; } int get() const { return ii; } - + static int sget(const A_T& a) { return a.ii; } }; } diff --git a/Examples/test-suite/python/implicittest_runme.py b/Examples/test-suite/python/implicittest_runme.py new file mode 100644 index 000000000..4200543c4 --- /dev/null +++ b/Examples/test-suite/python/implicittest_runme.py @@ -0,0 +1,73 @@ +from implicittest import * + +def check(a, b): + if a != b: + raise RuntimeError(str(a) + " does not equal " + str(b)) + +#### Class #### + +# No implicit conversion +check(1, A(1).get()) +check(2, A(1.0).get()) +check(3, A(B()).get()) +check(4, A("hello").get()) + +check(1, get(1)) +check(2, get(1.0)) +check(3, get(B())) + +# Explicit constructor: +try: + check(4, get("hello")) + raise RuntimeError +except TypeError: + pass + +#### Template Class #### + +# No implicit conversion +check(1, A_int(1).get()) +check(2, A_int(1.0).get()) +check(3, A_int(B()).get()) +check(4, A_int("hello").get()) + +check(1, A_int.sget(1)) +check(2, A_int.sget(1.0)) +check(3, A_int.sget(B())) + +# explicit constructor: +try: + check(4, A_int.sget("hello")) + raise RuntimeError +except TypeError: + pass + +#### Global variable assignment #### + +cvar.foo = Foo(1); check(cvar.foo.ii, 1) +cvar.foo = 1; check(cvar.foo.ii, 1) +cvar.foo = 1.0; check(cvar.foo.ii, 2) +cvar.foo = Foo("hello"); check(cvar.foo.ii, 3) + +# explicit constructor: +try: + cvar.foo = "hello" + raise RuntimeError +except TypeError: + pass + +#### Member variable assignment #### +# Note: also needs naturalvar + +b = Bar(); check(b.f.ii, 0) +b.f = Foo("hello"); check(b.f.ii, 3) +b.f = 1; check(b.f.ii, 1) +b.f = 1.0; check(b.f.ii, 2) + +# explicit constructor: +try: + b.f = "hello" + raise RuntimeError +except TypeError: + pass + -- cgit v1.2.1