Skip to content

Commit

Permalink
add joystick + touch
Browse files Browse the repository at this point in the history
  • Loading branch information
ellraiser committed Dec 4, 2023
1 parent 73c89a1 commit 1562e3d
Show file tree
Hide file tree
Showing 3 changed files with 119 additions and 3 deletions.
8 changes: 5 additions & 3 deletions main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ if love.filesystem ~= nil then require('tests.filesystem') end
if love.font ~= nil then require('tests.font') end
if love.graphics ~= nil then require('tests.graphics') end
if love.image ~= nil then require('tests.image') end
if love.joystick ~= nil then require('tests.joystick') end
if love.keyboard ~= nil then require('tests.keyboard') end
if love.math ~= nil then require('tests.math') end
if love.physics ~= nil then require('tests.physics') end
Expand All @@ -23,6 +24,7 @@ if love.sound ~= nil then require('tests.sound') end
if love.system ~= nil then require('tests.system') end
if love.thread ~= nil then require('tests.thread') end
if love.timer ~= nil then require('tests.timer') end
if love.touch ~= nil then require('tests.touch') end
if love.video ~= nil then require('tests.video') end
if love.window ~= nil then require('tests.window') end

Expand Down Expand Up @@ -72,9 +74,9 @@ love.load = function(args)
local method = ''
local cmderr = 'Invalid flag used'
local modules = {
'audio', 'data', 'event', 'filesystem', 'font', 'graphics',
'image', 'keyboard', 'math', 'physics', 'sensor', 'sound', 'system',
'thread', 'timer', 'video', 'window'
'audio', 'data', 'event', 'filesystem', 'font', 'graphics', 'image',
'joystick', 'keyboard', 'math', 'physics', 'sensor', 'sound', 'system',
'thread', 'timer', 'touch', 'video', 'window'
}
GITHUB_RUNNER = false
for a=1,#arglist do
Expand Down
81 changes: 81 additions & 0 deletions tests/joystick.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
-- love.joystick
-- @NOTE we can't test this module fully as it's hardware dependent
-- however we can test methods do what is expected and can handle certain params

--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
------------------------------------METHODS-------------------------------------
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------


-- love.joystick.getGamepadMappingString
love.test.joystick.getGamepadMappingString = function(test)
local mapping = love.joystick.getGamepadMappingString('faker')
test:assertEquals(nil, mapping, 'check no mapping for fake gui')
end


-- love.joystick.getJoystickCount
love.test.joystick.getJoystickCount = function(test)
local count = love.joystick.getJoystickCount()
test:assertEquals(0, count, 'check no joysticks')
end


-- love.joystick.getJoysticks
love.test.joystick.getJoysticks = function(test)
local joysticks = love.joystick.getJoysticks()
test:assertEquals(0, #joysticks, 'check no joysticks')
end


-- love.joystick.loadGamepadMappings
love.test.joystick.loadGamepadMappings = function(test)
local ok, err = pcall(love.joystick.loadGamepadMappings, 'fakefile.txt')
test:assertEquals(false, ok, 'check invalid file')
love.joystick.loadGamepadMappings('resources/mappings.txt')
end


-- love.joystick.saveGamepadMappings
love.test.joystick.saveGamepadMappings = function(test)
love.joystick.loadGamepadMappings('resources/mappings.txt')
local mapping = love.joystick.saveGamepadMappings()
test:assertGreaterEqual(0, #mapping, 'check something mapped')
end


-- love.joystick.setGamepadMapping
love.test.joystick.setGamepadMapping = function(test)
local guid = '030000005e040000130b000011050000'
local mappings = {
love.joystick.setGamepadMapping(guid, 'a', 'button', 1, nil),
love.joystick.setGamepadMapping(guid, 'b', 'button', 2, nil),
love.joystick.setGamepadMapping(guid, 'x', 'button', 3, nil),
love.joystick.setGamepadMapping(guid, 'y', 'button', 4, nil),
love.joystick.setGamepadMapping(guid, 'back', 'button', 5, nil),
love.joystick.setGamepadMapping(guid, 'start', 'button', 6, nil),
love.joystick.setGamepadMapping(guid, 'guide', 'button', 7, nil),
love.joystick.setGamepadMapping(guid, 'leftstick', 'button', 8, nil),
love.joystick.setGamepadMapping(guid, 'leftshoulder', 'button', 9, nil),
love.joystick.setGamepadMapping(guid, 'rightstick', 'button', 10, nil),
love.joystick.setGamepadMapping(guid, 'rightshoulder', 'button', 11, nil),
love.joystick.setGamepadMapping(guid, 'dpup', 'button', 12, nil),
love.joystick.setGamepadMapping(guid, 'dpdown', 'button', 13, nil),
love.joystick.setGamepadMapping(guid, 'dpleft', 'button', 14, nil),
love.joystick.setGamepadMapping(guid, 'dpright', 'button', 15, nil),
love.joystick.setGamepadMapping(guid, 'dpup', 'button', 12, 'u'),
love.joystick.setGamepadMapping(guid, 'dpdown', 'button', 13, 'd'),
love.joystick.setGamepadMapping(guid, 'dpleft', 'button', 14, 'l'),
love.joystick.setGamepadMapping(guid, 'dpright', 'button', 15, 'r'),
love.joystick.setGamepadMapping(guid, 'dpup', 'hat', 12, 'lu'),
love.joystick.setGamepadMapping(guid, 'dpdown', 'hat', 13, 'ld'),
love.joystick.setGamepadMapping(guid, 'dpleft', 'hat', 14, 'ru'),
love.joystick.setGamepadMapping(guid, 'dpright', 'hat', 15, 'rd'),
love.joystick.setGamepadMapping(guid, 'leftstick', 'axis', 8, 'c')
}
for m=1,#mappings do
test:assertEquals(true, mappings[m], 'check mapping #' .. tostring(m))
end
end
33 changes: 33 additions & 0 deletions tests/touch.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
-- love.touch
-- @NOTE we can't test this module fully as it's hardware dependent
-- however we can test methods do what is expected and can handle certain params

--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
------------------------------------METHODS-------------------------------------
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------


-- love.touch.getPosition
-- @TODO is there a way to fake the touchid pointer?
love.test.touch.getPosition = function(test)
test:assertNotNil(love.touch.getPosition)
test:assertEquals('function', type(love.touch.getPosition))
end


-- love.touch.getPressure
-- @TODO is there a way to fake the touchid pointer?
love.test.touch.getPressure = function(test)
test:assertNotNil(love.touch.getPressure)
test:assertEquals('function', type(love.touch.getPressure))
end


-- love.touch.getTouches
love.test.touch.getTouches = function(test)
local touches = love.touch.getTouches()
test:assertNotNil(touches)
test:assertEquals(0, #touches, 'check no touches')
end

0 comments on commit 1562e3d

Please sign in to comment.