joystick.lua 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. -- love.joystick
  2. -- @NOTE we can't test this module fully as it's hardware dependent
  3. -- however we can test methods do what is expected and can handle certain params
  4. --------------------------------------------------------------------------------
  5. --------------------------------------------------------------------------------
  6. ------------------------------------METHODS-------------------------------------
  7. --------------------------------------------------------------------------------
  8. --------------------------------------------------------------------------------
  9. -- love.joystick.getGamepadMappingString
  10. love.test.joystick.getGamepadMappingString = function(test)
  11. local mapping = love.joystick.getGamepadMappingString('faker')
  12. test:assertEquals(nil, mapping, 'check no mapping for fake gui')
  13. end
  14. -- love.joystick.getJoystickCount
  15. love.test.joystick.getJoystickCount = function(test)
  16. local count = love.joystick.getJoystickCount()
  17. test:assertEquals(0, count, 'check no joysticks')
  18. end
  19. -- love.joystick.getJoysticks
  20. love.test.joystick.getJoysticks = function(test)
  21. local joysticks = love.joystick.getJoysticks()
  22. test:assertEquals(0, #joysticks, 'check no joysticks')
  23. end
  24. -- love.joystick.loadGamepadMappings
  25. love.test.joystick.loadGamepadMappings = function(test)
  26. local ok, err = pcall(love.joystick.loadGamepadMappings, 'fakefile.txt')
  27. test:assertEquals(false, ok, 'check invalid file')
  28. love.joystick.loadGamepadMappings('resources/mappings.txt')
  29. end
  30. -- love.joystick.saveGamepadMappings
  31. love.test.joystick.saveGamepadMappings = function(test)
  32. love.joystick.loadGamepadMappings('resources/mappings.txt')
  33. local mapping = love.joystick.saveGamepadMappings()
  34. test:assertGreaterEqual(0, #mapping, 'check something mapped')
  35. end
  36. -- love.joystick.setGamepadMapping
  37. love.test.joystick.setGamepadMapping = function(test)
  38. local guid = '030000005e040000130b000011050000'
  39. local mappings = {
  40. love.joystick.setGamepadMapping(guid, 'a', 'button', 1, nil),
  41. love.joystick.setGamepadMapping(guid, 'b', 'button', 2, nil),
  42. love.joystick.setGamepadMapping(guid, 'x', 'button', 3, nil),
  43. love.joystick.setGamepadMapping(guid, 'y', 'button', 4, nil),
  44. love.joystick.setGamepadMapping(guid, 'back', 'button', 5, nil),
  45. love.joystick.setGamepadMapping(guid, 'start', 'button', 6, nil),
  46. love.joystick.setGamepadMapping(guid, 'guide', 'button', 7, nil),
  47. love.joystick.setGamepadMapping(guid, 'leftstick', 'button', 8, nil),
  48. love.joystick.setGamepadMapping(guid, 'leftshoulder', 'button', 9, nil),
  49. love.joystick.setGamepadMapping(guid, 'rightstick', 'button', 10, nil),
  50. love.joystick.setGamepadMapping(guid, 'rightshoulder', 'button', 11, nil),
  51. love.joystick.setGamepadMapping(guid, 'dpup', 'button', 12, nil),
  52. love.joystick.setGamepadMapping(guid, 'dpdown', 'button', 13, nil),
  53. love.joystick.setGamepadMapping(guid, 'dpleft', 'button', 14, nil),
  54. love.joystick.setGamepadMapping(guid, 'dpright', 'button', 15, nil),
  55. love.joystick.setGamepadMapping(guid, 'dpup', 'button', 12, 'u'),
  56. love.joystick.setGamepadMapping(guid, 'dpdown', 'button', 13, 'd'),
  57. love.joystick.setGamepadMapping(guid, 'dpleft', 'button', 14, 'l'),
  58. love.joystick.setGamepadMapping(guid, 'dpright', 'button', 15, 'r'),
  59. love.joystick.setGamepadMapping(guid, 'dpup', 'hat', 12, 'lu'),
  60. love.joystick.setGamepadMapping(guid, 'dpdown', 'hat', 13, 'ld'),
  61. love.joystick.setGamepadMapping(guid, 'dpleft', 'hat', 14, 'ru'),
  62. love.joystick.setGamepadMapping(guid, 'dpright', 'hat', 15, 'rd'),
  63. love.joystick.setGamepadMapping(guid, 'leftstick', 'axis', 8, 'c')
  64. }
  65. for m=1,#mappings do
  66. test:assertEquals(true, mappings[m], 'check mapping #' .. tostring(m))
  67. end
  68. end