Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Dirty test for BizHawk / LuaInterface
- local ret
- local tmp
- -- varargs test
- local log = console.logz -- vargs version of console.log
- if log then
- console.log("--------------------")
- console.log("Expected output: (empty line)")
- log()
- console.log("--------------------")
- console.log("Expected output: 1")
- log("1")
- console.log("--------------------")
- console.log("Expected output: 1 2 NULL 4")
- log("1", "2", nil, "4")
- console.log("--------------------")
- console.log("Expected output: 1 2 NULL 4 NULL")
- log("1", "2", nil, "4", nil)
- console.log("--------------------")
- else
- console.log("Function for vargs is not set, test skipped.")
- end
- -- test for function without params
- tmp = mainmemory.getname()
- console.log("mainmemory.getname() = " .. tmp)
- console.log("--------------------")
- -- give a parameter (will raise error)
- ret, tmp = pcall(mainmemory.getname, 1)
- if ret then
- console.log("mainmemory.getname(1) = " .. tmp .. " (TEST FAILED)")
- else
- console.log("mainmemory.getname(1) => " .. tostring(tmp) .. " (TEST SUCCEEDED)")
- end
- console.log("--------------------")
- -- test for function with 1 optional param
- tmp = joypad.get()
- console.log("joypad.get()")
- console.log("--------------------")
- tmp = joypad.get(1)
- console.log("joypad.get(1)")
- console.log("--------------------")
- ret, tmp = pcall(joypad.get, 1, 2)
- if ret then
- console.log("joypad.get(1, 2) => (TEST FAILED)")
- else
- console.log("joypad.get(1, 2) => " .. tostring(tmp) .. " (TEST SUCCEEDED)")
- end
- console.log("--------------------")
- -- test for function with 1 mandatory and 1 optional params
- ret, tmp = pcall(joypad.set)
- if ret then
- console.log("joypad.set() => (TEST FAILED)")
- else
- console.log("joypad.set() => " .. tostring(tmp) .. " (TEST SUCCEEDED)")
- end
- console.log("--------------------")
- tmp = joypad.set({})
- console.log("joypad.set({})")
- console.log("--------------------")
- tmp = joypad.set({}, 1)
- console.log("joypad.set({}, 1)")
- console.log("--------------------")
- ret, tmp = pcall(joypad.set, {}, 1, 2)
- if ret then
- console.log("joypad.set({}, 1, 2) => (TEST FAILED)")
- else
- console.log("joypad.set({}, 1, 2) => " .. tostring(tmp) .. " (TEST SUCCEEDED)")
- end
- console.log("--------------------")
- -- type check
- ret, tmp = pcall(joypad.set, "1")
- if ret then
- console.log("joypad.set(\"1\") => (TEST FAILED)")
- else
- console.log("joypad.set(\"1\") => " .. tostring(tmp) .. " (TEST SUCCEEDED)")
- end
- console.log("--------------------")
- ret, tmp = pcall(joypad.set, {}, "1")
- if ret then
- console.log("joypad.set({},\"1\") => (TEST FAILED)")
- else
- console.log("joypad.set({},\"1\") => " .. tostring(tmp) .. " (TEST SUCCEEDED)")
- end
- console.log("--------------------")
- ret, tmp = pcall(mainmemory.readbyte, "1")
- if ret then
- console.log("mainmemory.readbyte(\"1\") => (TEST FAILED)")
- else
- console.log("mainmemory.readbyte(\"1\") => " .. tostring(tmp) .. " (TEST SUCCEEDED)")
- end
- console.log("--------------------")
- ret, tmp = pcall(mainmemory.readbyte, {})
- if ret then
- console.log("mainmemory.readbyte({}) => (TEST FAILED)")
- else
- console.log("mainmemory.readbyte({}) => " .. tostring(tmp) .. " (TEST SUCCEEDED)")
- end
- console.log("--------------------")
- -- Firstly I thought the following code will raise an error, but that was not true.
- ret, tmp = pcall(joypad.set, 1)
- if ret then
- console.log("joypad.set(1) => (TEST SUCCEEDED)")
- else
- console.log("joypad.set(1) => " .. tostring(tmp) .. " (TEST FAILED)")
- end
- console.log("--------------------")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement