aboutsummaryrefslogtreecommitdiff
path: root/engines/sword25/util/pluto/puptest.lua
diff options
context:
space:
mode:
authorJohannes Schickel2010-10-13 03:57:44 +0000
committerJohannes Schickel2010-10-13 03:57:44 +0000
commit75e8452b6e6a2bf4fb2f588aa00b428a60d873b5 (patch)
treef29541d55309487a94bd1d38e8b53bb3dde9aec6 /engines/sword25/util/pluto/puptest.lua
parent48ee83b88957dab86bc763e9ef21a70179fa8679 (diff)
parente9f50882ea5b6beeefa994040be9d3bab6a1f107 (diff)
downloadscummvm-rg350-75e8452b6e6a2bf4fb2f588aa00b428a60d873b5.tar.gz
scummvm-rg350-75e8452b6e6a2bf4fb2f588aa00b428a60d873b5.tar.bz2
scummvm-rg350-75e8452b6e6a2bf4fb2f588aa00b428a60d873b5.zip
OPENGL: Merged from trunk, from rev 52105 to 53396.
This includes an rather hacky attempt to merge all the recent gp2x backend changes into the branch. I suppose the gp2x backend and probably all new backends, i.e. gph, dingux etc., might not compile anymore. Since I have no way of testing those it would be nice if porters could look into getting those up to speed in this branch. svn-id: r53399
Diffstat (limited to 'engines/sword25/util/pluto/puptest.lua')
-rw-r--r--engines/sword25/util/pluto/puptest.lua93
1 files changed, 93 insertions, 0 deletions
diff --git a/engines/sword25/util/pluto/puptest.lua b/engines/sword25/util/pluto/puptest.lua
new file mode 100644
index 0000000000..e5ccdd64bd
--- /dev/null
+++ b/engines/sword25/util/pluto/puptest.lua
@@ -0,0 +1,93 @@
+-- $Id$
+
+require "pluto"
+
+permtable = { 1234 }
+
+perms = { [1] = coroutine.yield, [2] = permtable }
+
+function testcounter(counter)
+ local a = counter.cur()
+ counter.inc()
+ return counter.cur() == a+1
+end
+
+function testuvinthread(func)
+ local success, result = coroutine.resume(func)
+ return success and result == 5
+end
+
+
+function test(rootobj)
+ local passed = 0
+ local total = 0
+ local dotest = function(name,cond)
+ total = total+1
+ if cond then
+ print(name, " PASSED")
+ passed = passed + 1
+ else
+ print(name, "* FAILED")
+ end
+ end
+
+
+ dotest("Boolean FALSE ", rootobj.testfalse == false)
+ dotest("Boolean TRUE ", rootobj.testtrue == true)
+ dotest("Number 7 ", rootobj.testseven == 7)
+ dotest("String 'foobar' ", rootobj.testfoobar == "foobar")
+ dotest("Func returning 4 ", rootobj.testfuncreturnsfour() == 4)
+ dotest("Nil value ", rootobj.testnil == nil)
+ dotest("Thread resume ", coroutine.resume(rootobj.testthread) == true,14)
+ dotest("Table ", rootobj.testtbl.a == 2 and rootobj.testtbl[2] == 4);
+ dotest("Permanent table ", rootobj.testperm == permtable)
+ dotest("Table metatable ", rootobj.testmt() == 21)
+ dotest("Function env ", rootobj.testfenv() == 456)
+ dotest("Lua closure ", rootobj.testclosure() == 11)
+ dotest("Nil in closure ", rootobj.testnilclosure() == nil)
+ dotest("Nested func ", rootobj.testnest(1) == 6)
+ dotest("Light userdata ", checkludata(rootobj.testludata))
+ dotest("Looped tables ",
+ rootobj.testlooptable.testloopb.testloopa ==
+ rootobj.testlooptable)
+ dotest("Shared reference ", rootobj.testsharedrefa.sharedref ==
+ rootobj.testsharedrefb.sharedref)
+ dotest("Identical tables ", rootobj.testsharedrefa ~=
+ rootobj.testsharedrefb)
+ dotest("Table special persist", rootobj.testsptable.a == 6)
+ dotest("Udata literal persist",
+ unboxinteger(rootobj.testliteraludata) == 71)
+ dotest("Udata special persist",
+ unboxboolean(rootobj.testspudata1) == true and
+ unboxboolean(rootobj.testspudata2) == false)
+ dotest("Shared upvalues ",
+ testcounter(rootobj.testsharedupval))
+ dotest("Open upvalues ",
+ testuvinthread(rootobj.testuvinthread))
+ dotest("Upvalue cycles ",
+ rootobj.testuvcycle()[1] == rootobj.testuvcycle()[2])
+ dotest("__newindex metamethod", rootobj.testniinmt.a == 3)
+ dotest("Debug info ", (rootobj.testdebuginfo(2)) == "foo")
+ print()
+ if passed == total then
+ print("All tests passed.")
+ else
+ print(passed .. "/" .. total .. " tests passed.")
+ end
+end
+
+infile, err = io.open("test.plh", "rb")
+if infile == nil then
+ error("While opening: " .. (err or "no error"))
+end
+
+buf, err = infile:read("*a")
+if buf == nil then
+ error("While reading: " .. (err or "no error"))
+end
+
+infile:close()
+
+rootobj = pluto.unpersist(perms, buf)
+
+test(rootobj)