event.lua 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. -- love.event
  2. -- love.event.clear
  3. love.test.event.clear = function(test)
  4. -- push some events first
  5. love.event.push('test', 1, 2, 3)
  6. love.event.push('test', 1, 2, 3)
  7. love.event.push('test', 1, 2, 3)
  8. -- check after calling clear there are no events left
  9. love.event.clear()
  10. local count = 0
  11. for n, a, b, c, d, e, f in love.event.poll() do
  12. count = count + 1
  13. end
  14. test:assertEquals(0, count, 'check no events')
  15. end
  16. -- love.event.poll
  17. love.test.event.poll = function(test)
  18. -- push some events first
  19. love.event.push('test', 1, 2, 3)
  20. love.event.push('test', 1, 2, 3)
  21. love.event.push('test', 1, 2, 3)
  22. -- check poll recieves all events
  23. local count = 0
  24. for n, a, b, c, d, e, f in love.event.poll() do
  25. count = count + 1
  26. end
  27. test:assertEquals(3, count, 'check 3 events')
  28. end
  29. -- love.event.pump
  30. -- @NOTE dont think can really test as internally used
  31. love.test.event.pump = function(test)
  32. test:skipTest('not sure can be tested as used internally')
  33. end
  34. -- love.event.push
  35. love.test.event.push = function(test)
  36. -- check pushing some different types
  37. love.event.push('add', 1, 2, 3)
  38. love.event.push('ignore', 1, 2, 3)
  39. love.event.push('add', 1, 2, 3)
  40. love.event.push('ignore', 1, 2, 3)
  41. local count = 0
  42. for n, a, b, c, d, e, f in love.event.poll() do
  43. if n == 'add' then
  44. count = count + a + b + c
  45. end
  46. end
  47. test:assertEquals(12, count, 'check total events')
  48. end
  49. -- love.event.quit
  50. love.test.event.quit = function(test)
  51. -- setting this overrides the quit hook to prevent actually quitting
  52. love.test.module.fakequit = true
  53. love.event.quit(0)
  54. -- if it failed we'd have quit here
  55. test:assertEquals(true, true, 'check quit hook called')
  56. end
  57. -- love.event.wait
  58. -- @NOTE not sure best way to test this one
  59. love.test.event.wait = function(test)
  60. test:skipTest('test class needs writing')
  61. end