[lua] fixed bug in template classes which cases template_default2 and template_specialization_defarg to fail.

Added several warning filters into the overload's test cases.
Added runtime tests for several codes.
You can now make check-lua-test-suite with no errors and only a few warnings.

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@10076 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
Mark Gossage 2007-10-30 06:10:04 +00:00
commit 0c2bbb25a3
19 changed files with 368 additions and 15 deletions

View file

@ -0,0 +1,55 @@
require("import") -- the import fn
import("overload_simple") -- import code
for k,v in pairs(overload_simple) do _G[k]=v end -- move to global
-- lua has only one numeric type, foo(int) and foo(double) are the same
-- whichever one was wrapper first will be used
assert(foo(3)=="foo:int" or foo(3)=="foo:double") -- could be either
assert(foo("hello")=="foo:char *")
f=Foo()
b=Bar()
assert(foo(f)=="foo:Foo *")
assert(foo(b)=="foo:Bar *")
v = malloc_void(32)
assert(foo(v) == "foo:void *")
s = Spam()
assert(s:foo(3) == "foo:int" or s:foo(3.0) == "foo:double") -- could be either
assert(s:foo("hello") == "foo:char *")
assert(s:foo(f) == "foo:Foo *")
assert(s:foo(b) == "foo:Bar *")
assert(s:foo(v) == "foo:void *")
assert(Spam_bar(3) == "bar:int" or Spam_bar(3.0) == "bar:double")
assert(Spam_bar("hello") == "bar:char *")
assert(Spam_bar(f) == "bar:Foo *")
assert(Spam_bar(b) == "bar:Bar *")
assert(Spam_bar(v) == "bar:void *")
-- Test constructors
s = Spam()
assert(s.type == "none")
s = Spam(3)
assert(s.type == "int" or s.type == "double")
s = Spam("hello")
assert(s.type == "char *")
s = Spam(f)
assert(s.type == "Foo *")
s = Spam(b)
assert(s.type == "Bar *")
s = Spam(v)
assert(s.type == "void *")
free_void(v)

View file

@ -0,0 +1,81 @@
require("import") -- the import fn
import("overload_template_fast") -- import code
for k,v in pairs(overload_template_fast) do _G[k]=v end -- move to global
-- lua has only one numeric type, so max(int,int) and max(double,double) are the same
-- whichever one was wrapper first will be used (which is int)
f = foo()
a = max(3,4)
-- mix 1
assert(mix1("hi") == 101)
assert(mix1(1.0, 1.0) == 102)
assert(mix1(1.0) == 103)
-- mix 2
assert(mix2("hi") == 101)
assert(mix2(1.0, 1.0) == 102)
assert(mix2(1.0) == 103)
-- mix 3
assert(mix3("hi") == 101)
assert(mix3(1.0, 1.0) == 102)
assert(mix3(1.0) == 103)
-- Combination 1
assert(overtparams1(100) == 10)
assert(overtparams1(100.0, 100) == 20)
-- Combination 2
assert(overtparams2(100.0, 100) == 40)
-- Combination 3
assert(overloaded() == 60)
assert(overloaded(100.0, 100) == 70)
-- Combination 4
assert(overloadedagain("hello") == 80)
assert(overloadedagain() == 90)
-- specializations
assert(specialization(10) == 202 or specialization(10.0) == 203) -- only one works
assert(specialization(10, 10) == 204 or specialization(10.0, 10.0) == 205) -- ditto
assert(specialization("hi", "hi") == 201)
-- simple specialization
xyz()
xyz_int()
xyz_double()
-- a bit of everything
assert(overload("hi") == 0)
assert(overload(1) == 10)
assert(overload(1, 1) == 20)
assert(overload(1, "hello") == 30)
k = Klass()
assert(overload(k) == 10)
assert(overload(k, k) == 20)
assert(overload(k, "hello") == 30)
-- this one is incorrect: it mactches overload(10.0, "hi") with int overload(T t, const char *c)
--print(overload(10.0, "hi"))
--assert(overload(10.0, "hi") == 40)
assert(overload() == 50)
-- everything put in a namespace
assert(nsoverload("hi") == 1000,"nsoverload()")
assert(nsoverload(1) == 1010,"nsoverload(int t)")
assert(nsoverload(1, 1) == 1020,"nsoverload(int t, const int &)")
assert(nsoverload(1, "hello") == 1030,"nsoverload(int t, const char *)")
assert(nsoverload(k) == 1010,"nsoverload(Klass t)")
assert(nsoverload(k, k) == 1020,"nsoverload(Klass t, const Klass &)")
assert(nsoverload(k, "hello") == 1030,"nsoverload(Klass t, const char *)")
-- again this one fails
--assert(nsoverload(10.0, "hi") == 1040,"nsoverload(double t, const char *)")
assert(nsoverload() == 1050,"nsoverload(const char *)")
A_foo(1)
b = B()
b:foo(1)

View file

@ -0,0 +1,81 @@
require("import") -- the import fn
import("overload_template") -- import code
for k,v in pairs(overload_template) do _G[k]=v end -- move to global
-- lua has only one numeric type, so max(int,int) and max(double,double) are the same
-- whichever one was wrapper first will be used (which is int)
f = foo()
a = max(3,4)
-- mix 1
assert(mix1("hi") == 101)
assert(mix1(1.0, 1.0) == 102)
assert(mix1(1.0) == 103)
-- mix 2
assert(mix2("hi") == 101)
assert(mix2(1.0, 1.0) == 102)
assert(mix2(1.0) == 103)
-- mix 3
assert(mix3("hi") == 101)
assert(mix3(1.0, 1.0) == 102)
assert(mix3(1.0) == 103)
-- Combination 1
assert(overtparams1(100) == 10)
assert(overtparams1(100.0, 100) == 20)
-- Combination 2
assert(overtparams2(100.0, 100) == 40)
-- Combination 3
assert(overloaded() == 60)
assert(overloaded(100.0, 100) == 70)
-- Combination 4
assert(overloadedagain("hello") == 80)
assert(overloadedagain() == 90)
-- specializations
assert(specialization(10) == 202 or specialization(10.0) == 203) -- only one works
assert(specialization(10, 10) == 204 or specialization(10.0, 10.0) == 205) -- ditto
assert(specialization("hi", "hi") == 201)
-- simple specialization
xyz()
xyz_int()
xyz_double()
-- a bit of everything
assert(overload("hi") == 0)
assert(overload(1) == 10)
assert(overload(1, 1) == 20)
assert(overload(1, "hello") == 30)
k = Klass()
assert(overload(k) == 10)
assert(overload(k, k) == 20)
assert(overload(k, "hello") == 30)
-- this one is incorrect: it mactches overload(10.0, "hi") with int overload(T t, const char *c)
--print(overload(10.0, "hi"))
--assert(overload(10.0, "hi") == 40)
assert(overload() == 50)
-- everything put in a namespace
assert(nsoverload("hi") == 1000,"nsoverload()")
assert(nsoverload(1) == 1010,"nsoverload(int t)")
assert(nsoverload(1, 1) == 1020,"nsoverload(int t, const int &)")
assert(nsoverload(1, "hello") == 1030,"nsoverload(int t, const char *)")
assert(nsoverload(k) == 1010,"nsoverload(Klass t)")
assert(nsoverload(k, k) == 1020,"nsoverload(Klass t, const Klass &)")
assert(nsoverload(k, "hello") == 1030,"nsoverload(Klass t, const char *)")
-- again this one fails
--assert(nsoverload(10.0, "hi") == 1040,"nsoverload(double t, const char *)")
assert(nsoverload() == 1050,"nsoverload(const char *)")
A_foo(1)
b = B()
b:foo(1)

View file

@ -0,0 +1,14 @@
require("import") -- the import fn
import("smart_pointer_overload") -- import code
for k,v in pairs(smart_pointer_overload) do _G[k]=v end -- move to global
f = Foo()
b = Bar(f)
assert(f:test(3) == 1)
--assert(f:test(3.5) == 2) -- won't work due to being unable to overloads
assert(f:test("hello") == 3)
assert(b:test(3) == 1)
--assert(b:test(3.5) == 2) -- won't work due to being unable to overloads
assert(b:test("hello") == 3)

View file

@ -0,0 +1,63 @@
require("import") -- the import fn
import("template_default_arg") -- import code
--for k,v in pairs(template_default_arg) do _G[k]=v end -- move to global
helloInt = template_default_arg.Hello_int()
helloInt:foo(template_default_arg.Hello_int_hi)
x = template_default_arg.X_int()
assert(x:meth(20.0, 200) == 200,"X_int test 1 failed")
assert(x:meth(20) == 20,"X_int test 2 failed")
assert(x:meth() == 0,"X_int test 3 failed")
y = template_default_arg.Y_unsigned()
assert(y:meth(20.0, 200) == 200,"Y_unsigned test 1 failed")
assert(y:meth(20) == 20,"Y_unsigned test 2 failed")
assert(y:meth() == 0,"Y_unsigned test 3 failed")
x = template_default_arg.X_longlong()
x = template_default_arg.X_longlong(20.0)
x = template_default_arg.X_longlong(20.0, 200) -- note: long longs just treated as another number
x = template_default_arg.X_int()
x = template_default_arg.X_int(20.0)
x = template_default_arg.X_int(20.0, 200)
x = template_default_arg.X_hello_unsigned()
x = template_default_arg.X_hello_unsigned(20.0)
x = template_default_arg.X_hello_unsigned(20.0, template_default_arg.Hello_int())
y = template_default_arg.Y_hello_unsigned()
y:meth(20.0, template_default_arg.Hello_int())
y:meth(template_default_arg.Hello_int())
y:meth()
fz = template_default_arg.Foo_Z_8()
x = template_default_arg.X_Foo_Z_8()
fzc = x:meth(fz)
-- Templated functions
-- plain function: int ott(Foo<int>)
assert(template_default_arg.ott(template_default_arg.Foo_int()) == 30,"ott test 1 failed")
-- %template(ott) ott<int, int>
assert(template_default_arg.ott() == 10,"ott test 2 failed")
assert(template_default_arg.ott(1) == 10,"ott test 3 failed")
assert(template_default_arg.ott(1, 1) == 10,"ott test 4 failed")
assert(template_default_arg.ott("hi") == 20,"ott test 5 failed")
assert(template_default_arg.ott("hi", 1) == 20,"ott test 6 failed")
assert(template_default_arg.ott("hi", 1, 1) == 20,"ott test 7 failed")
-- %template(ott) ott<const char *>
assert(template_default_arg.ottstring(template_default_arg.Hello_int(), "hi") == 40,"ott test 8 failed")
assert(template_default_arg.ottstring(template_default_arg.Hello_int()) == 40,"ott test 9 failed")
-- %template(ott) ott<int>
assert(template_default_arg.ottint(template_default_arg.Hello_int(), 1) == 50,"ott test 10 failed")
assert(template_default_arg.ottint(template_default_arg.Hello_int()) == 50,"ott test 11 failed")
-- %template(ott) ott<double>
assert(template_default_arg.ott(template_default_arg.Hello_int(), 1.0) == 60,"ott test 12 failed")
assert(template_default_arg.ott(template_default_arg.Hello_int()) == 60,"ott test 13 failed")