fixed test case: dynamic_casts, exception_partial_info, li_std_string, size_t
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@9636 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
6ffd26cc1e
commit
e545d7b957
6 changed files with 77 additions and 10 deletions
15
Examples/test-suite/lua/dynamic_cast_runme.lua
Normal file
15
Examples/test-suite/lua/dynamic_cast_runme.lua
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
require("import") -- the import fn
|
||||
import("dynamic_cast") -- import code
|
||||
|
||||
f = dynamic_cast.Foo()
|
||||
b = dynamic_cast.Bar()
|
||||
|
||||
x = f:blah()
|
||||
y = b:blah()
|
||||
|
||||
-- swig_type is a swiglua specific function which gets the swig_type_info's name
|
||||
assert(swig_type(f)==swig_type(x))
|
||||
assert(swig_type(b)==swig_type(y))
|
||||
|
||||
-- the real test: is y a Foo* or a Bar*?
|
||||
assert(dynamic_cast.do_test(y)=="Bar::test")
|
||||
|
|
@ -12,19 +12,34 @@ function try1()
|
|||
a:foo()
|
||||
end
|
||||
|
||||
ok,ex=pcall(try1)
|
||||
assert(ok==false and swig_type(ex)==swig_type(eo.E1()))
|
||||
|
||||
function try2()
|
||||
a:bar()
|
||||
end
|
||||
ok,ex=pcall(try2)
|
||||
assert(ok==false and swig_type(ex)==swig_type(eo.E2()))
|
||||
|
||||
function try3()
|
||||
a:foobar()
|
||||
end
|
||||
|
||||
-- the following code used to work
|
||||
-- but now no longer works, as the lua bindings don't throw objects any more
|
||||
-- all objects are converted to string & thrown
|
||||
-- it could be made to work, if E1 & E2 were thrown by value (see lua.swg)
|
||||
--[[
|
||||
ok,ex=pcall(try1)
|
||||
print(ok,ex)
|
||||
assert(ok==false and swig_type(ex)==swig_type(eo.E1()))
|
||||
|
||||
ok,ex=pcall(try2)
|
||||
assert(ok==false and swig_type(ex)==swig_type(eo.E2()))
|
||||
]]
|
||||
-- this new code does work, but has to look at the string
|
||||
ok,ex=pcall(try1)
|
||||
assert(ok==false and ex=="object exception:E1")
|
||||
|
||||
ok,ex=pcall(try2)
|
||||
assert(ok==false and ex=="object exception:E2")
|
||||
|
||||
-- the SWIG_exception is just an error string
|
||||
ok,ex=pcall(try3)
|
||||
assert(ok==false and type(ex)=="string")
|
||||
-- the SWIG_exception is just an error string
|
||||
|
||||
|
|
|
|||
12
Examples/test-suite/lua/exception_partial_info_runme.lua
Normal file
12
Examples/test-suite/lua/exception_partial_info_runme.lua
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
require("import") -- the import fn
|
||||
import("exception_partial_info") -- import code
|
||||
|
||||
-- catch "undefined" global variables
|
||||
setmetatable(getfenv(),{__index=function (t,i) error("undefined global variable `"..i.."'",2) end})
|
||||
|
||||
imp=exception_partial_info.Impl()
|
||||
|
||||
-- trying to call throwing methods
|
||||
-- should fail
|
||||
assert(pcall(function() imp:f1() end)==false)
|
||||
assert(pcall(function() imp:f2() end)==false)
|
||||
16
Examples/test-suite/lua/li_std_except_runme.lua
Normal file
16
Examples/test-suite/lua/li_std_except_runme.lua
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
require("import") -- the import fn
|
||||
import("li_std_except") -- import code
|
||||
|
||||
test = li_std_except.Test()
|
||||
-- under lua, all the std::exceptions are just turned to strings, so we are only checking that is fails
|
||||
assert(pcall(function() test:throw_bad_exception() end)==false)
|
||||
assert(pcall(function() test:throw_domain_error() end)==false)
|
||||
assert(pcall(function() test:throw_exception() end)==false)
|
||||
assert(pcall(function() test:throw_invalid_argument() end)==false)
|
||||
assert(pcall(function() test:throw_length_error() end)==false)
|
||||
assert(pcall(function() test:throw_logic_error() end)==false)
|
||||
assert(pcall(function() test:throw_out_of_range() end)==false)
|
||||
assert(pcall(function() test:throw_overflow_error() end)==false)
|
||||
assert(pcall(function() test:throw_range_error() end)==false)
|
||||
assert(pcall(function() test:throw_runtime_error() end)==false)
|
||||
assert(pcall(function() test:throw_underflow_error() end)==false)
|
||||
|
|
@ -49,14 +49,14 @@ assert(ok==false and type(ex)=="string") -- failed & threw string
|
|||
ok,ex=pcall(test_const_reference_throw)
|
||||
assert(ok==false and type(ex)=="string") -- failed & threw string
|
||||
|
||||
-- const ptrs are thrown as str::string**
|
||||
-- not quite right
|
||||
-- const ptrs are now converted to lua strings
|
||||
-- they used to be std::string*
|
||||
ok,ex=pcall(test_const_pointer_throw)
|
||||
assert(ok==false and type(ex)=="userdata") -- failed & threw object
|
||||
assert(ok==false and type(ex)=="string") -- failed & threw object
|
||||
|
||||
-- ditto non const ptrs
|
||||
ok,ex=pcall(test_pointer_throw)
|
||||
assert(ok==false and type(ex)=="userdata") -- failed & threw object
|
||||
assert(ok==false and type(ex)=="string") -- failed & threw object
|
||||
|
||||
-- testing std::string variables
|
||||
-- Global variables
|
||||
|
|
|
|||
9
Examples/test-suite/lua/sizet_runme.lua
Normal file
9
Examples/test-suite/lua/sizet_runme.lua
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
require("import") -- the import fn
|
||||
import("sizet") -- import code
|
||||
|
||||
s = 2000
|
||||
s = sizet.test1(s+1)
|
||||
s = sizet.test2(s+1)
|
||||
s = sizet.test3(s+1)
|
||||
s = sizet.test4(s+1)
|
||||
assert(s == 2004)
|
||||
Loading…
Add table
Add a link
Reference in a new issue