Advertisement
gocha

Test for BizHawk / LuaInterface (vargs support)

Apr 28th, 2014
207
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.50 KB | None | 0 0
  1. -- Dirty test for BizHawk / LuaInterface
  2.  
  3. local ret
  4. local tmp
  5.  
  6. -- varargs test
  7. local log = console.logz -- vargs version of console.log
  8. if log then
  9.   console.log("--------------------")
  10.   console.log("Expected output: (empty line)")
  11.   log()
  12.   console.log("--------------------")
  13.   console.log("Expected output: 1")
  14.   log("1")
  15.   console.log("--------------------")
  16.   console.log("Expected output: 1 2 NULL 4")
  17.   log("1", "2", nil, "4")
  18.   console.log("--------------------")
  19.   console.log("Expected output: 1 2 NULL 4 NULL")
  20.   log("1", "2", nil, "4", nil)
  21.   console.log("--------------------")
  22. else
  23.   console.log("Function for vargs is not set, test skipped.")
  24. end
  25.  
  26. -- test for function without params
  27. tmp = mainmemory.getname()
  28. console.log("mainmemory.getname() = " .. tmp)
  29. console.log("--------------------")
  30. -- give a parameter (will raise error)
  31. ret, tmp = pcall(mainmemory.getname, 1)
  32. if ret then
  33.   console.log("mainmemory.getname(1) = " .. tmp .. " (TEST FAILED)")
  34. else
  35.   console.log("mainmemory.getname(1) => " .. tostring(tmp) .. " (TEST SUCCEEDED)")
  36. end
  37. console.log("--------------------")
  38.  
  39. -- test for function with 1 optional param
  40. tmp = joypad.get()
  41. console.log("joypad.get()")
  42. console.log("--------------------")
  43. tmp = joypad.get(1)
  44. console.log("joypad.get(1)")
  45. console.log("--------------------")
  46. ret, tmp = pcall(joypad.get, 1, 2)
  47. if ret then
  48.   console.log("joypad.get(1, 2) => (TEST FAILED)")
  49. else
  50.   console.log("joypad.get(1, 2) => " .. tostring(tmp) .. " (TEST SUCCEEDED)")
  51. end
  52. console.log("--------------------")
  53.  
  54. -- test for function with 1 mandatory and 1 optional params
  55. ret, tmp = pcall(joypad.set)
  56. if ret then
  57.   console.log("joypad.set() => (TEST FAILED)")
  58. else
  59.   console.log("joypad.set() => " .. tostring(tmp) .. " (TEST SUCCEEDED)")
  60. end
  61. console.log("--------------------")
  62. tmp = joypad.set({})
  63. console.log("joypad.set({})")
  64. console.log("--------------------")
  65. tmp = joypad.set({}, 1)
  66. console.log("joypad.set({}, 1)")
  67. console.log("--------------------")
  68. ret, tmp = pcall(joypad.set, {}, 1, 2)
  69. if ret then
  70.   console.log("joypad.set({}, 1, 2) => (TEST FAILED)")
  71. else
  72.   console.log("joypad.set({}, 1, 2) => " .. tostring(tmp) .. " (TEST SUCCEEDED)")
  73. end
  74. console.log("--------------------")
  75.  
  76. -- type check
  77. ret, tmp = pcall(joypad.set, "1")
  78. if ret then
  79.   console.log("joypad.set(\"1\") => (TEST FAILED)")
  80. else
  81.   console.log("joypad.set(\"1\") => " .. tostring(tmp) .. " (TEST SUCCEEDED)")
  82. end
  83. console.log("--------------------")
  84. ret, tmp = pcall(joypad.set, {}, "1")
  85. if ret then
  86.   console.log("joypad.set({},\"1\") => (TEST FAILED)")
  87. else
  88.   console.log("joypad.set({},\"1\") => " .. tostring(tmp) .. " (TEST SUCCEEDED)")
  89. end
  90. console.log("--------------------")
  91. ret, tmp = pcall(mainmemory.readbyte, "1")
  92. if ret then
  93.   console.log("mainmemory.readbyte(\"1\") => (TEST FAILED)")
  94. else
  95.   console.log("mainmemory.readbyte(\"1\") => " .. tostring(tmp) .. " (TEST SUCCEEDED)")
  96. end
  97. console.log("--------------------")
  98. ret, tmp = pcall(mainmemory.readbyte, {})
  99. if ret then
  100.   console.log("mainmemory.readbyte({}) => (TEST FAILED)")
  101. else
  102.   console.log("mainmemory.readbyte({}) => " .. tostring(tmp) .. " (TEST SUCCEEDED)")
  103. end
  104. console.log("--------------------")
  105. -- Firstly I thought the following code will raise an error, but that was not true.
  106. ret, tmp = pcall(joypad.set, 1)
  107. if ret then
  108.   console.log("joypad.set(1) => (TEST SUCCEEDED)")
  109. else
  110.   console.log("joypad.set(1) => " .. tostring(tmp) .. " (TEST FAILED)")
  111. end
  112. console.log("--------------------")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement