system.lua 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. -- love.system
  2. --------------------------------------------------------------------------------
  3. --------------------------------------------------------------------------------
  4. ----------------------------------METHODS---------------------------------------
  5. --------------------------------------------------------------------------------
  6. --------------------------------------------------------------------------------
  7. -- love.system.getClipboardText
  8. love.test.system.getClipboardText = function(test)
  9. -- ignore if not using window
  10. if love.test.windowmode == false then
  11. return test:skipTest('clipboard only available in window mode')
  12. end
  13. -- check clipboard value is set
  14. love.system.setClipboardText('helloworld')
  15. test:assertEquals('helloworld', love.system.getClipboardText(), 'check clipboard match')
  16. end
  17. -- love.system.getOS
  18. love.test.system.getOS = function(test)
  19. -- check os is in documented values
  20. local os = love.system.getOS()
  21. local options = {'OS X', 'Windows', 'Linux', 'Android', 'iOS'}
  22. test:assertMatch(options, os, 'check value matches')
  23. end
  24. -- love.system.getPowerInfo
  25. love.test.system.getPowerInfo = function(test)
  26. -- check battery state is one of the documented states
  27. local state, percent, seconds = love.system.getPowerInfo()
  28. local states = {'unknown', 'battery', 'nobattery', 'charging', 'charged'}
  29. test:assertMatch(states, state, 'check value matches')
  30. -- if percent/seconds check within expected range
  31. if percent ~= nil then
  32. test:assertRange(percent, 0, 100, 'check battery percent within range')
  33. end
  34. if seconds ~= nil then
  35. test:assertNotNil(seconds)
  36. end
  37. end
  38. -- love.system.getProcessorCount
  39. love.test.system.getProcessorCount = function(test)
  40. test:assertNotNil(love.system.getProcessorCount()) -- youd hope right
  41. end
  42. -- love.system.hasBackgroundMusic
  43. love.test.system.hasBackgroundMusic = function(test)
  44. test:assertNotNil(love.system.hasBackgroundMusic())
  45. end
  46. -- love.system.openURL
  47. love.test.system.openURL = function(test)
  48. test:skipTest('cant test this worked')
  49. --test:assertNotEquals(nil, love.system.openURL('https://love2d.org'), 'check open URL')
  50. end
  51. -- love.system.getClipboardText
  52. love.test.system.setClipboardText = function(test)
  53. -- ignore if not using window
  54. if love.test.windowmode == false then
  55. return test:skipTest('clipboard only available in window mode')
  56. end
  57. -- check value returned is what was set
  58. love.system.setClipboardText('helloworld')
  59. test:assertEquals('helloworld', love.system.getClipboardText(), 'check set text')
  60. end
  61. -- love.system.vibrate
  62. -- @NOTE cant really test this
  63. love.test.system.vibrate = function(test)
  64. test:skipTest('cant test this worked')
  65. end