First banch of tests
This commit is contained in:
parent
efe1d8aea7
commit
dfc02f306d
14 changed files with 385 additions and 0 deletions
27
Examples/test-suite/lua/cpp_namespace_runme.lua
Normal file
27
Examples/test-suite/lua/cpp_namespace_runme.lua
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
require("import") -- the import fn
|
||||
import("cpp_namespace") -- import lib into global
|
||||
cn=cpp_namespace --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( cn.fact(4) == 24 )
|
||||
assert( cn.Foo == 42 )
|
||||
|
||||
t1 = cn.Test()
|
||||
assert( t1:method() == "Test::method" )
|
||||
|
||||
cn.weird("t1", 4)
|
||||
|
||||
assert( cn.do_method(t1) == "Test::method" )
|
||||
assert( cn.do_method2(t1) == "Test::method" )
|
||||
|
||||
t2 = cn.Test2()
|
||||
assert( t2:method() == "Test2::method" )
|
||||
|
||||
|
||||
assert( cn.foo3(5) == 5 )
|
||||
|
||||
assert( cn.do_method3(t2, 7) == "Test2::method" )
|
||||
24
Examples/test-suite/lua/cpp_nodefault_runme.lua
Normal file
24
Examples/test-suite/lua/cpp_nodefault_runme.lua
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
-- Run file
|
||||
require("import") -- the import fn
|
||||
import("cpp_nodefault") -- import lib into global
|
||||
cn=cpp_nodefault --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 = cn.Foo(1,2)
|
||||
foo1.a = 5
|
||||
assert(foo1.a == 5)
|
||||
|
||||
foo2 = cn.create(1,2)
|
||||
|
||||
cn.consume(foo1,foo2)
|
||||
|
||||
bar1 = cn.Bar()
|
||||
bar1:consume( cn.gvar, foo2)
|
||||
foo3 = bar1:create(1,2)
|
||||
|
||||
foo3.a = 6
|
||||
assert( foo3.a == 6 )
|
||||
16
Examples/test-suite/lua/cpp_static_runme.lua
Normal file
16
Examples/test-suite/lua/cpp_static_runme.lua
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
-- demo of lua swig capacilities (operator overloading)
|
||||
require("import") -- the import fn
|
||||
import("cpp_static") -- import lib into global
|
||||
cs=cpp_static --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})
|
||||
|
||||
cs.StaticMemberTest.static_int = 5;
|
||||
assert(cs.StaticMemberTest.static_int == 5);
|
||||
|
||||
cs.StaticFunctionTest.static_func()
|
||||
cs.StaticFunctionTest.static_func_2(2)
|
||||
cs.StaticFunctionTest.static_func_3(3,3)
|
||||
23
Examples/test-suite/lua/cpp_typedef_runme.lua
Normal file
23
Examples/test-suite/lua/cpp_typedef_runme.lua
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
|
||||
require("import") -- the import fn
|
||||
import("cpp_typedef") -- import lib into global
|
||||
ct = cpp_typedef --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 = ct.Foo()
|
||||
bar1 = foo1:bar()
|
||||
bar2 = ct.Foo.sbar()
|
||||
|
||||
u1 = ct.UnnamedStruct()
|
||||
n1 = ct.TypedefNamedStruct()
|
||||
|
||||
test = ct.Test()
|
||||
|
||||
u2 = test:test1(u1)
|
||||
n2 = test:test2(n1)
|
||||
n3 = test:test3(n1)
|
||||
n4 = test:test4(n1)
|
||||
|
|
@ -0,0 +1,32 @@
|
|||
require("import") -- the import fn
|
||||
import("extend_constructor_destructor") -- import lib into global
|
||||
ecd=extend_constructor_destructor --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})
|
||||
|
||||
a1 = ecd.AStruct(101)
|
||||
assert(a1.ivar == 101)
|
||||
assert(ecd.globalVar == 101)
|
||||
|
||||
b1 = ecd.BStruct(201)
|
||||
assert(b1.ivar == 201)
|
||||
assert(ecd.globalVar == 201)
|
||||
|
||||
c1 = ecd.CStruct(301)
|
||||
assert(c1.ivar == 301)
|
||||
assert(ecd.globalVar == 301)
|
||||
|
||||
d1 = ecd.DStruct(401)
|
||||
assert(d1.ivar == 401)
|
||||
assert(ecd.globalVar == 401)
|
||||
|
||||
e1 = ecd.EStruct(501)
|
||||
assert(e1.ivar == 501)
|
||||
assert(ecd.globalVar == 501)
|
||||
|
||||
f1 = ecd.FStruct(601)
|
||||
assert(f1.ivar == 601)
|
||||
assert(ecd.globalVar == 601)
|
||||
37
Examples/test-suite/lua/extend_placement_runme.lua
Normal file
37
Examples/test-suite/lua/extend_placement_runme.lua
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
require("import") -- the import fn
|
||||
import("extend_placement") -- import lib into global
|
||||
ep=extend_placement --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})
|
||||
|
||||
function test_obj( main, suppl )
|
||||
assert(main:spam() == 1)
|
||||
assert(main:spam("this_is_string") == 2)
|
||||
assert(main:spam(5) == 5)
|
||||
assert(main:spam(5,6) == 11)
|
||||
assert(main:spam( 7,8,9) == 15)
|
||||
assert(main:spam(suppl,12.0) == 0)
|
||||
assert(main:spam(suppl) == 0)
|
||||
end
|
||||
|
||||
foo1 = ep.Foo(0)
|
||||
foo2 = ep.Foo(1,2)
|
||||
foo3 = ep.Foo()
|
||||
test_obj(foo1,foo2)
|
||||
|
||||
|
||||
bar1 = ep.Bar()
|
||||
bar2 = ep.Bar(5)
|
||||
test_obj(bar1,bar2)
|
||||
|
||||
fti1 = ep.FooTi(0)
|
||||
fti2 = ep.FooTi(1,2)
|
||||
fti3 = ep.FooTi()
|
||||
test_obj(fti1,foo1)
|
||||
|
||||
bti1 = ep.BarTi()
|
||||
bti2 = ep.BarTi(5)
|
||||
test_obj(bti1,bar1)
|
||||
28
Examples/test-suite/lua/extend_runme.lua
Normal file
28
Examples/test-suite/lua/extend_runme.lua
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
require("import") -- the import fn
|
||||
import("extend") -- import lib into global
|
||||
e=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})
|
||||
|
||||
base1 = e.Base()
|
||||
assert(base1.value == 0)
|
||||
base2 = e.Base(10)
|
||||
assert(base2.value == 10)
|
||||
|
||||
assert(base1:method(5) == 5)
|
||||
assert(e.Base.zeroVal() == 0)
|
||||
assert(base2:currentValue() == 10)
|
||||
assert(base2:extendmethod(7) == 14)
|
||||
|
||||
der1 = e.Derived(0)
|
||||
assert(der1.value == 0)
|
||||
assert(der1:method(5) == 10)
|
||||
|
||||
der2 = e.Derived(17)
|
||||
assert(der2.value == 34)
|
||||
der2.extendval = 200.0
|
||||
assert( math.abs(der2.actualval - 2.0) < 0.001 )
|
||||
assert( math.abs(der2.extendval - 200.0) < 0.001 )
|
||||
12
Examples/test-suite/lua/extend_template_runme.lua
Normal file
12
Examples/test-suite/lua/extend_template_runme.lua
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
require("import") -- the import fn
|
||||
import("extend_template") -- import lib into global
|
||||
et=extend_template--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 = et.Foo_0()
|
||||
assert(foo1:test1(5) == 5)
|
||||
assert(foo1:test2(7) == 7)
|
||||
37
Examples/test-suite/lua/extend_typedef_class_runme.lua
Normal file
37
Examples/test-suite/lua/extend_typedef_class_runme.lua
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
require("import") -- the import fn
|
||||
import("extend_typedef_class") -- import lib into global
|
||||
etc=extend_typedef_class --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})
|
||||
|
||||
function test_obj( obj, const )
|
||||
obj.membervar = const
|
||||
assert(obj:getvar() == const)
|
||||
end
|
||||
|
||||
a1 = etc.AClass()
|
||||
test_obj(a1,1)
|
||||
|
||||
b1 = etc.BClass()
|
||||
test_obj(b1,2)
|
||||
|
||||
c1 = etc.CClass()
|
||||
test_obj(c1,3)
|
||||
|
||||
d1 = etc.DClass()
|
||||
test_obj(d1,4)
|
||||
|
||||
a2 = etc.AStruct()
|
||||
test_obj(a2,5)
|
||||
|
||||
b2 = etc.BStruct()
|
||||
test_obj(b2,6)
|
||||
|
||||
c2 = etc.CStruct()
|
||||
test_obj(c2,7)
|
||||
|
||||
d2 = etc.DStruct()
|
||||
test_obj(d2,8)
|
||||
29
Examples/test-suite/lua/extend_variable_runme.lua
Normal file
29
Examples/test-suite/lua/extend_variable_runme.lua
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
require("import") -- the import fn
|
||||
import("extend_variable") -- import lib into global
|
||||
ev=extend_variable --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})
|
||||
|
||||
e1 = ev.ExtendMe()
|
||||
answ = 1.0
|
||||
assert( e1:set(7.0) )
|
||||
--assert( e1:get(answ) ) -- doesn't work. Lua can't pass primitive type by non-const reference
|
||||
--assert( answ == 7.0 )
|
||||
|
||||
e1.ExtendVar = 5.0
|
||||
assert(e1.ExtendVar == 5.0)
|
||||
|
||||
assert(ev.Foo.Bar == 42)
|
||||
assert(ev.Foo.AllBarOne == 4422)
|
||||
|
||||
assert(ev.Foo.StaticInt == 1111)
|
||||
ev.Foo.StaticInt = 3333
|
||||
assert(ev.Foo.StaticInt == 3333)
|
||||
|
||||
assert(ev.Foo.StaticConstInt == 2222)
|
||||
|
||||
b1 = ev.Bar()
|
||||
assert(b1.x == 1)
|
||||
27
Examples/test-suite/lua/friends_runme.lua
Normal file
27
Examples/test-suite/lua/friends_runme.lua
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
require("import") -- the import fn
|
||||
import("friends") -- import lib into global
|
||||
f=friends --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})
|
||||
|
||||
f.globalscope()
|
||||
|
||||
b1 = f.B(5)
|
||||
a1 = f.A(10)
|
||||
|
||||
assert(f.get_val1(a1) == 10)
|
||||
assert(f.get_val1(a1, 2) == 12)
|
||||
assert(f.get_val2(a1) == 20)
|
||||
assert(f.get_val3(a1) == 30)
|
||||
|
||||
assert(f.get_val1(100, 1, 2) == 100)
|
||||
|
||||
assert( f.mix(a1,b1) == 15);
|
||||
|
||||
d1 = f.D_i(7)
|
||||
assert(f.get_val1(d1) == 7)
|
||||
f.set(d1,9)
|
||||
assert(f.get_val1(d1) == 9)
|
||||
18
Examples/test-suite/lua/funcptr_cpp_runme.lua
Normal file
18
Examples/test-suite/lua/funcptr_cpp_runme.lua
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
require("import") -- the import fn
|
||||
import("funcptr_cpp") -- import lib into global
|
||||
fc=funcptr_cpp --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( fc.addByValue(5,10) == 15)
|
||||
-- These two won't work. Lua will successfully store the answer as userdata, but there is
|
||||
-- no way of accessing the insides of userdata.
|
||||
-- assert( fc.addByPointer(7, 9) == 16)
|
||||
-- assert( fc.addByReference(8, 9) == 17)
|
||||
|
||||
assert( fc.call1(fc.ADD_BY_VALUE, 5, 10) == 15)
|
||||
assert( fc.call2(fc.ADD_BY_POINTER, 7, 9) == 16)
|
||||
assert( fc.call3(fc.ADD_BY_REFERENCE, 8, 9) == 17)
|
||||
17
Examples/test-suite/lua/fvirtual_runme.lua
Normal file
17
Examples/test-suite/lua/fvirtual_runme.lua
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
require("import") -- the import fn
|
||||
import("fvirtual") -- import lib into global
|
||||
f=fvirtual --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})
|
||||
|
||||
n1 = f.Node()
|
||||
n2 = f.Node()
|
||||
assert(n1:addChild(n2) == 1)
|
||||
|
||||
ns = f.NodeSwitch()
|
||||
assert(ns:addChild(n2) == 2)
|
||||
assert(ns:addChild(ns) == 2)
|
||||
assert(ns:addChild(n1, false) == 3)
|
||||
58
Examples/test-suite/lua/global_namespace_runme.lua
Normal file
58
Examples/test-suite/lua/global_namespace_runme.lua
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
require("import") -- the import fn
|
||||
import("global_namespace") -- import lib into global
|
||||
gn=global_namespace --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})
|
||||
|
||||
k1 = gn.Klass1()
|
||||
k2 = gn.Klass2()
|
||||
k3 = gn.Klass3()
|
||||
k4 = gn.Klass4()
|
||||
k5 = gn.Klass5()
|
||||
k6 = gn.Klass6()
|
||||
k7 = gn.Klass7()
|
||||
|
||||
gn.KlassMethods.methodA(k1,k2,k3,k4,k5,k6,k7)
|
||||
gn.KlassMethods.methodB(k1,k2,k3,k4,k5,k6,k7)
|
||||
|
||||
k1 = gn.getKlass1A()
|
||||
k2 = gn.getKlass2A()
|
||||
k3 = gn.getKlass3A()
|
||||
k4 = gn.getKlass4A()
|
||||
k5 = gn.getKlass5A()
|
||||
k6 = gn.getKlass6A()
|
||||
k7 = gn.getKlass7A()
|
||||
|
||||
gn.KlassMethods.methodA(k1,k2,k3,k4,k5,k6,k7)
|
||||
gn.KlassMethods.methodB(k1,k2,k3,k4,k5,k6,k7)
|
||||
|
||||
k1 = gn.getKlass1B()
|
||||
k2 = gn.getKlass2B()
|
||||
k3 = gn.getKlass3B()
|
||||
k4 = gn.getKlass4B()
|
||||
k5 = gn.getKlass5B()
|
||||
k6 = gn.getKlass6B()
|
||||
k7 = gn.getKlass7B()
|
||||
|
||||
gn.KlassMethods.methodA(k1,k2,k3,k4,k5,k6,k7)
|
||||
gn.KlassMethods.methodB(k1,k2,k3,k4,k5,k6,k7)
|
||||
|
||||
x1 = gn.XYZ1()
|
||||
x2 = gn.XYZ2()
|
||||
x3 = gn.XYZ3()
|
||||
x4 = gn.XYZ4()
|
||||
x5 = gn.XYZ5()
|
||||
x6 = gn.XYZ6()
|
||||
x7 = gn.XYZ7()
|
||||
|
||||
gn.XYZMethods.methodA(x1,x2,x3,x4,x5,x6,x7)
|
||||
gn.XYZMethods.methodB(x1,x2,x3,x4,x5,x6,x7)
|
||||
|
||||
gn.AnEnumMethods.methodA(gn.anenum1, gn.anenum2, gn.anenum3)
|
||||
gn.AnEnumMethods.methodB(gn.anenum1, gn.anenum2, gn.anenum3)
|
||||
|
||||
gn.TheEnumMethods.methodA(gn.theenum1, gn.theenum2, gn.theenum3)
|
||||
gn.TheEnumMethods.methodB(gn.theenum1, gn.theenum2, gn.theenum3)
|
||||
Loading…
Add table
Add a link
Reference in a new issue