diff options
author | Artem Serebriyskiy <v.for.vandal@gmail.com> | 2013-10-31 23:25:40 +0400 |
---|---|---|
committer | William S Fulton <wsf@fultondesigns.co.uk> | 2013-11-09 14:54:34 +0000 |
commit | c9279ab0e77dbc9a565b0a427fb9b5f36472b6b5 (patch) | |
tree | 92feed2d704c61e8b2590a579d420e71bed7a13e | |
parent | dfc02f306de0de87042991e6d6afedf587219af0 (diff) | |
download | swig-c9279ab0e77dbc9a565b0a427fb9b5f36472b6b5.tar.gz |
More tests
16 files changed, 296 insertions, 0 deletions
diff --git a/Examples/test-suite/keyword_rename.i b/Examples/test-suite/keyword_rename.i index 6a6082ff9..46c3338b3 100644 --- a/Examples/test-suite/keyword_rename.i +++ b/Examples/test-suite/keyword_rename.i @@ -31,6 +31,10 @@ struct sealed {int i;}; KW(go, defer) KW(chan, fallthrough) +/* Lua keywords */ +KW(end, function) +KW(nil,local) + %} diff --git a/Examples/test-suite/lua/grouping_runme.lua b/Examples/test-suite/lua/grouping_runme.lua new file mode 100644 index 000000000..798a7359e --- /dev/null +++ b/Examples/test-suite/lua/grouping_runme.lua @@ -0,0 +1,17 @@ +require("import") -- the import fn +import("grouping") -- import lib into global +g=grouping --alias + +-- catching undefined variables +local env = _ENV -- Lua 5.2 +if not env then env = getfenv () end -- Lua 5.1 +setmetatable(env, {__index=function (t,i) error("undefined global variable `"..i.."'",2) end}) + +assert( g.test1(5) == 5 ) +g.test2(42) -- Return value is int* packed into userdata. We can't do anything with it + +assert( g.test3 == 37 ) +g.test3 = 42 +assert( g.test3 == 42 ) + +assert( g.do_unary(5, g.NEGATE) == -5 ) diff --git a/Examples/test-suite/lua/iadd_runme.lua b/Examples/test-suite/lua/iadd_runme.lua new file mode 100644 index 000000000..556644061 --- /dev/null +++ b/Examples/test-suite/lua/iadd_runme.lua @@ -0,0 +1,17 @@ +require("import") -- the import fn +import("iadd") -- import lib into global +i=iadd --alias + +-- catching undefined variables +local env = _ENV -- Lua 5.2 +if not env then env = getfenv () end -- Lua 5.1 +setmetatable(env, {__index=function (t,i) error("undefined global variable `"..i.."'",2) end}) + +foo1 = i.Foo() +foo1_a = foo1.AsA +assert( foo1_a.x == 5 ) +assert( foo1_a:get_me().x == 5 ) +-- Unfortunately, in Lua operator+= can't be overloaded + +foo1.AsLong = 1000 +assert( foo1.AsLong == 1000 ) diff --git a/Examples/test-suite/lua/keyword_rename_runme.lua b/Examples/test-suite/lua/keyword_rename_runme.lua new file mode 100644 index 000000000..5d54ef123 --- /dev/null +++ b/Examples/test-suite/lua/keyword_rename_runme.lua @@ -0,0 +1,16 @@ +require("import") -- the import fn +import("keyword_rename") -- import lib into global +kn=keyword_rename--alias + +-- catching undefined variables +local env = _ENV -- Lua 5.2 +if not env then env = getfenv () end -- Lua 5.1 +setmetatable(env, {__index=function (t,i) error("undefined global variable `"..i.."'",2) end}) + + +-- assert( kn.end(5) == 5 ) -- Curretly SWIG/Lua doesn't rename keywords +-- assert( kn.nil(7) == 7 ) + +-- But you can always access wrongly named members using string constants +assert( kn["end"](5) == 5 ) +assert( kn["nil"](7) == 7 ) diff --git a/Examples/test-suite/lua/overload_complicated_runme.lua b/Examples/test-suite/lua/overload_complicated_runme.lua new file mode 100644 index 000000000..5670607bf --- /dev/null +++ b/Examples/test-suite/lua/overload_complicated_runme.lua @@ -0,0 +1,22 @@ +require("import") -- the import fn +import("overload_complicated") -- import lib into global +oc=overload_complicated --alias + +-- catching undefined variables +local env = _ENV -- Lua 5.2 +if not env then env = getfenv () end -- Lua 5.1 +setmetatable(env, {__index=function (t,i) error("undefined global variable `"..i.."'",2) end}) + +assert( oc.foo(1,1,"test",1) == 15 ) + +p1 = oc.Pop(nil) +p1 = oc.Pop(nil,false) + +assert( p1:hip(true) == 701 ) +assert( p1:hip(nil) == 702 ) + +assert( p1:hop(true) == 801 ) +assert( p1:hop(nil) == 805 ) + +assert( oc.muzak(true) == 3001 ) +assert( oc.muzak(nil) == 3002 ) diff --git a/Examples/test-suite/lua/smart_pointer_extend_runme.lua b/Examples/test-suite/lua/smart_pointer_extend_runme.lua new file mode 100644 index 000000000..6d33c57b1 --- /dev/null +++ b/Examples/test-suite/lua/smart_pointer_extend_runme.lua @@ -0,0 +1,34 @@ +require("import") -- the import fn +import("smart_pointer_extend") -- import lib into global +spe=smart_pointer_extend --alias + +-- catching undefined variables +local env = _ENV -- Lua 5.2 +if not env then env = getfenv () end -- Lua 5.1 +setmetatable(env, {__index=function (t,i) error("undefined global variable `"..i.."'",2) end}) + +assert( spe.CBase.hello() == 1 ) +assert( spe.CBase.z == 1 ) + +base1 = spe.CBase() +base1.x = 7 + +p1 = spe.CPtr() + +assert( spe.get_hello(p1) == 1 ) +assert( p1:foo() == 1 ) +assert( p1:bar() == 2 ) +assert( p1:boo(5) == 5 ) + +foo = spe.Foo() +bar = spe.Bar(foo) + +assert( bar:extension(5,7) == 5 ) +assert( bar:extension(7) == 7 ) +assert( bar:extension() == 1 ) + +dfoo = spe.DFoo() +dptr = spe.DPtrFoo(dfoo) + +assert( dptr:Ext() == 2 ) +assert( dptr:Ext(5) == 5 ) diff --git a/Examples/test-suite/lua/smart_pointer_inherit_runme.lua b/Examples/test-suite/lua/smart_pointer_inherit_runme.lua new file mode 100644 index 000000000..75510ad08 --- /dev/null +++ b/Examples/test-suite/lua/smart_pointer_inherit_runme.lua @@ -0,0 +1,18 @@ +require("import") -- the import fn +import("smart_pointer_inherit") -- import lib into global +spi=smart_pointer_inherit --alias + +-- catching undefined variables +local env = _ENV -- Lua 5.2 +if not env then env = getfenv () end -- Lua 5.1 +setmetatable(env, {__index=function (t,i) error("undefined global variable `"..i.."'",2) end}) + +der = spi.Derived(7) + +ptr = spi.SmartDerived(der) + +assert( ptr.val == 7 ) +assert( ptr:value() == 7 ) +assert( ptr:value2() == 7 ) +assert( ptr:value3() == 7 ) +assert( ptr:valuehide() == -1 ) diff --git a/Examples/test-suite/lua/smart_pointer_multi_runme.lua b/Examples/test-suite/lua/smart_pointer_multi_runme.lua new file mode 100644 index 000000000..ed3693727 --- /dev/null +++ b/Examples/test-suite/lua/smart_pointer_multi_runme.lua @@ -0,0 +1,23 @@ +require("import") -- the import fn +import("smart_pointer_multi") -- import lib into global +spm=smart_pointer_multi --alias + +-- catching undefined variables +local env = _ENV -- Lua 5.2 +if not env then env = getfenv () end -- Lua 5.1 +setmetatable(env, {__index=function (t,i) error("undefined global variable `"..i.."'",2) end}) + +foo = spm.Foo() +foo.x = 5 +assert( foo:getx() == 5 ) + +bar = spm.Bar(foo) +spam = spm.Spam(bar) +grok = spm.Grok(bar) + +assert( bar:getx() == 5 ) +assert( spam:getx() == 5 ) +spam.x = 7 +assert( grok:getx() == 7 ) +grok.x = 10 +assert( foo:getx() == 10 ) diff --git a/Examples/test-suite/lua/smart_pointer_not_runme.lua b/Examples/test-suite/lua/smart_pointer_not_runme.lua new file mode 100644 index 000000000..2f009a7f6 --- /dev/null +++ b/Examples/test-suite/lua/smart_pointer_not_runme.lua @@ -0,0 +1,25 @@ +require("import") -- the import fn +import("smart_pointer_not") -- import lib into global +spn=smart_pointer_not --alias + +-- catching undefined variables +local env = _ENV -- Lua 5.2 +if not env then env = getfenv () end -- Lua 5.1 +setmetatable(env, {__index=function (t,i) error("undefined global variable `"..i.."'",2) end}) + + +foo = spn.Foo() +foo.x = 7 +assert( foo:getx() == 7 ) + +bar = spn.Bar(foo) +success = pcall(bar.getx, bar) -- Bar is not a smart pointer. Call should fail +assert( not success ) + +spam = spn.Spam(foo) +success = pcall(spam.getx, spam) -- Spam is not a smart pointer. Call should fail +assert( not success ) + +grok = spn.Grok(foo) +success = pcall(grok.getx, grok) -- Spam is not a smart pointer. Call should fail +assert( not success ) diff --git a/Examples/test-suite/lua/smart_pointer_rename_runme.lua b/Examples/test-suite/lua/smart_pointer_rename_runme.lua new file mode 100644 index 000000000..51b07f61b --- /dev/null +++ b/Examples/test-suite/lua/smart_pointer_rename_runme.lua @@ -0,0 +1,18 @@ +require("import") -- the import fn +import("smart_pointer_rename") -- import lib into global +spr=smart_pointer_rename --alias + +-- catching undefined variables +local env = _ENV -- Lua 5.2 +if not env then env = getfenv () end -- Lua 5.1 +setmetatable(env, {__index=function (t,i) error("undefined global variable `"..i.."'",2) end}) + + +foo = spr.Foo() +assert( foo:ftest1(1) == 1 ) +assert( foo:ftest2(1,2) == 2 ) + +bar = spr.Bar(foo) +assert( bar:test() == 3 ) +assert( bar:ftest1(1) == 1 ) +assert( bar:ftest2(1,2) == 2 ) diff --git a/Examples/test-suite/lua/smart_pointer_simple_runme.lua b/Examples/test-suite/lua/smart_pointer_simple_runme.lua new file mode 100644 index 000000000..8513931b2 --- /dev/null +++ b/Examples/test-suite/lua/smart_pointer_simple_runme.lua @@ -0,0 +1,22 @@ +require("import") -- the import fn +import("smart_pointer_simple") -- import lib into global +sps=smart_pointer_simple --alias + +-- catching undefined variables +local env = _ENV -- Lua 5.2 +if not env then env = getfenv () end -- Lua 5.1 +setmetatable(env, {__index=function (t,i) error("undefined global variable `"..i.."'",2) end}) + +foo1 = sps.Foo() +foo1.x = 5 +assert( foo1.x == 5 ) +assert( foo1:getx() == 5 ) + +bar1 = sps.Bar(foo1) +bar1.x = 3 +assert(bar1.x == 3) +assert(bar1:getx() == 3) + +bar1.x = 5 +assert(bar1.x == 5) +assert(bar1:getx() == 5) diff --git a/Examples/test-suite/lua/smart_pointer_templatemethods_runme.lua b/Examples/test-suite/lua/smart_pointer_templatemethods_runme.lua new file mode 100644 index 000000000..018881c42 --- /dev/null +++ b/Examples/test-suite/lua/smart_pointer_templatemethods_runme.lua @@ -0,0 +1,18 @@ +require("import") -- the import fn +import("smart_pointer_templatemethods") -- import lib into global +spt=smart_pointer_templatemethods --alias + +-- catching undefined variables +local env = _ENV -- Lua 5.2 +if not env then env = getfenv () end -- Lua 5.1 +setmetatable(env, {__index=function (t,i) error("undefined global variable `"..i.."'",2) end}) + +o1 = spt.Objct() + +iid = spt.InterfaceId() + +po2 = o1:QueryInterfaceObjct(iid) +-- we can't call po2:DisposeObjct, because smart pointer Ptr<T> always return 0 when dereferencing +-- (see interface file). So we only check that po2 has necessary method +assert( po2.DisposeObjct ~= nil ) +assert( po2.QueryInterfaceObjct ~= nil ) diff --git a/Examples/test-suite/lua/template_construct_runme.lua b/Examples/test-suite/lua/template_construct_runme.lua new file mode 100644 index 000000000..aad9c3be4 --- /dev/null +++ b/Examples/test-suite/lua/template_construct_runme.lua @@ -0,0 +1,10 @@ +require("import") -- the import fn +import("template_construct") -- import lib into global +tc=template_construct --alias + +-- catching undefined variables +local env = _ENV -- Lua 5.2 +if not env then env = getfenv () end -- Lua 5.1 +setmetatable(env, {__index=function (t,i) error("undefined global variable `"..i.."'",2) end}) + +foo = tc.Foo_int(1) diff --git a/Examples/test-suite/lua/template_extend1_runme.lua b/Examples/test-suite/lua/template_extend1_runme.lua new file mode 100644 index 000000000..44774e949 --- /dev/null +++ b/Examples/test-suite/lua/template_extend1_runme.lua @@ -0,0 +1,14 @@ +require("import") -- the import fn +import("template_extend1") -- import lib into global +te=template_extend1 --alias + +-- catching undefined variables +local env = _ENV -- Lua 5.2 +if not env then env = getfenv () end -- Lua 5.1 +setmetatable(env, {__index=function (t,i) error("undefined global variable `"..i.."'",2) end}) + +lb = te.lBaz() +assert( lb:foo() == "lBaz::foo" ) + +db = te.dBaz() +assert( db:foo() == "dBaz::foo" ) diff --git a/Examples/test-suite/lua/template_extend2_runme.lua b/Examples/test-suite/lua/template_extend2_runme.lua new file mode 100644 index 000000000..23c25705b --- /dev/null +++ b/Examples/test-suite/lua/template_extend2_runme.lua @@ -0,0 +1,14 @@ +require("import") -- the import fn +import("template_extend2") -- import lib into global +te=template_extend2 --alias + +-- catching undefined variables +local env = _ENV -- Lua 5.2 +if not env then env = getfenv () end -- Lua 5.1 +setmetatable(env, {__index=function (t,i) error("undefined global variable `"..i.."'",2) end}) + +lb = te.lBaz() +assert( lb:foo() == "lBaz::foo" ) + +db = te.dBaz() +assert( db:foo() == "dBaz::foo" ) diff --git a/Examples/test-suite/lua/template_inherit_runme.lua b/Examples/test-suite/lua/template_inherit_runme.lua new file mode 100644 index 000000000..f2bfca00b --- /dev/null +++ b/Examples/test-suite/lua/template_inherit_runme.lua @@ -0,0 +1,24 @@ +require("import") -- the import fn +import("template_inherit") -- import lib into global +ti=template_inherit --alias + +-- catching undefined variables +local env = _ENV -- Lua 5.2 +if not env then env = getfenv () end -- Lua 5.1 +setmetatable(env, {__index=function (t,i) error("undefined global variable `"..i.."'",2) end}) + + +fi = ti.FooInt() +assert( fi:blah() == "Foo" ) +assert( fi:foomethod() == "foomethod" ) + +bi = ti.BarInt() +assert( bi:blah() == "Bar" ) +assert( bi:foomethod() == "foomethod" ) + +assert( ti.invoke_blah_int(fi) == "Foo" ) +assert( ti.invoke_blah_int(bi) == "Bar" ) + +bd = ti.BarDouble() +success = pcall( ti.invoke_blah_int, bd ) +assert( not success ) |