Add runtime test for %implicitconv

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13950 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
William S Fulton 2012-12-08 10:37:04 +00:00
commit ba575159f6
2 changed files with 74 additions and 2 deletions

View file

@ -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; }
};
}

View file

@ -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