diff options
author | William S Fulton <wsf@fultondesigns.co.uk> | 2012-12-08 10:37:04 +0000 |
---|---|---|
committer | William S Fulton <wsf@fultondesigns.co.uk> | 2012-12-08 10:37:04 +0000 |
commit | ba575159f6ae78a5353bd1408fed843ea8089e98 (patch) | |
tree | df50f9f4ac591d119c02b5c76cc9c7702e3d0fc4 /Examples/test-suite | |
parent | 8be65ec8e7d571a67715129298cfb9871232fd6f (diff) | |
download | swig-ba575159f6ae78a5353bd1408fed843ea8089e98.tar.gz |
Add runtime test for %implicitconv
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13950 626c5289-ae23-0410-ae9c-e8d60b6d4f22
Diffstat (limited to 'Examples/test-suite')
-rw-r--r-- | Examples/test-suite/implicittest.i | 3 | ||||
-rw-r--r-- | Examples/test-suite/python/implicittest_runme.py | 73 |
2 files changed, 74 insertions, 2 deletions
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 + |