system.lua 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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.getPreferredLocales
  25. love.test.system.getPreferredLocales = function(test)
  26. local locale = love.system.getPreferredLocales()
  27. test:assertNotNil(locale)
  28. test:assertEquals('table', type(locale), 'check returns table')
  29. end
  30. -- love.system.getPowerInfo
  31. love.test.system.getPowerInfo = function(test)
  32. -- check battery state is one of the documented states
  33. local state, percent, seconds = love.system.getPowerInfo()
  34. local states = {'unknown', 'battery', 'nobattery', 'charging', 'charged'}
  35. test:assertMatch(states, state, 'check value matches')
  36. -- if percent/seconds check within expected range
  37. if percent ~= nil then
  38. test:assertRange(percent, 0, 100, 'check battery percent within range')
  39. end
  40. if seconds ~= nil then
  41. test:assertNotNil(seconds)
  42. end
  43. end
  44. -- love.system.getProcessorCount
  45. love.test.system.getProcessorCount = function(test)
  46. test:assertNotNil(love.system.getProcessorCount()) -- youd hope right
  47. end
  48. -- love.system.hasBackgroundMusic
  49. love.test.system.hasBackgroundMusic = function(test)
  50. test:assertNotNil(love.system.hasBackgroundMusic())
  51. end
  52. -- love.system.openURL
  53. love.test.system.openURL = function(test)
  54. test:skipTest('cant test this worked')
  55. --test:assertNotEquals(nil, love.system.openURL('https://love2d.org'), 'check open URL')
  56. end
  57. -- love.system.getClipboardText
  58. love.test.system.setClipboardText = function(test)
  59. -- ignore if not using window
  60. if love.test.windowmode == false then
  61. return test:skipTest('clipboard only available in window mode')
  62. end
  63. -- check value returned is what was set
  64. love.system.setClipboardText('helloworld')
  65. test:assertEquals('helloworld', love.system.getClipboardText(), 'check set text')
  66. end
  67. -- love.system.vibrate
  68. -- @NOTE cant really test this
  69. love.test.system.vibrate = function(test)
  70. test:skipTest('cant test this worked')
  71. end