system.lua 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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.getMemorySize
  49. love.test.system.getMemorySize = function(test)
  50. test:assertNotNil(love.system.getMemorySize())
  51. end
  52. -- love.system.hasBackgroundMusic
  53. love.test.system.hasBackgroundMusic = function(test)
  54. test:assertNotNil(love.system.hasBackgroundMusic())
  55. end
  56. -- love.system.openURL
  57. love.test.system.openURL = function(test)
  58. test:skipTest('cant test this worked')
  59. --test:assertNotEquals(nil, love.system.openURL('https://love2d.org'), 'check open URL')
  60. end
  61. -- love.system.getClipboardText
  62. love.test.system.setClipboardText = function(test)
  63. -- ignore if not using window
  64. if love.test.windowmode == false then
  65. return test:skipTest('clipboard only available in window mode')
  66. end
  67. -- check value returned is what was set
  68. love.system.setClipboardText('helloworld')
  69. test:assertEquals('helloworld', love.system.getClipboardText(), 'check set text')
  70. end
  71. -- love.system.vibrate
  72. -- @NOTE cant really test this
  73. love.test.system.vibrate = function(test)
  74. test:skipTest('cant test this worked')
  75. end