Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Android Test Suites #2039

Draft
wants to merge 11 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,4 @@ stamp-h1
/src/tags
.vs/
.vscode/
/testing/output/*.xml
/testing/output/*.html
/testing/output/*.md
/testing/output/actual/*.png
/testing/output/
11 changes: 8 additions & 3 deletions testing/classes/TestMethod.lua
Original file line number Diff line number Diff line change
Expand Up @@ -270,10 +270,15 @@ TestMethod = {
-- @param {table} imgdata - imgdata to save as a png
-- @return {nil}
compareImg = function(self, imgdata)
local expected_path = 'tempoutput/expected/love.test.graphics.' ..
self.method .. '-' .. tostring(self.imgs) .. '.png'
local ok, chunk, _ = pcall(love.image.newImageData, expected_path)
local filename = 'love.test.graphics.' .. self.method .. '-' .. tostring(self.imgs) .. '.png'
local expected_path = 'resources/expected_output/' .. filename
local ok, chunk = pcall(love.filesystem.read, 'data', expected_path)
if ok == false then return self:assertEquals(true, false, chunk) end
local image_contents = chunk
ok, chunk = pcall(love.image.newImageData, chunk)
if ok == false then return self:assertEquals(true, false, chunk) end
-- Copy the expected file output to tempoutput/expected to keep HTML output working.
love.filesystem.write('tempoutput/expected/' .. filename, image_contents)
local expected = chunk
local iw = imgdata:getWidth()-2
local ih = imgdata:getHeight()-2
Expand Down
4 changes: 2 additions & 2 deletions testing/classes/TestSuite.lua
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ TestSuite = {

local status = '🔴'
if self.totals[2] == 0 then status = '🟢' end
local html = '<html><head><style>* { font-family: monospace; margin: 0; font-size: 11px; padding: 0; } body { margin: 50px; } h1 { padding-bottom: 10px; font-size: 13px; } h2 { padding: 20px 0 10px 0; font-size: 12px; } .summary { list-style: none; margin: 0; padding: 0; } .summary li { float: left; background: #eee; padding: 5px; margin-right: 10px; } table { background: #eee; margin-top: 10px; width: 100%; max-width: 800px; border-collapse: collapse } table thead { background: #ddd; } table th, table td { padding: 2px; } tr.red { color: red } .wrap { max-width: 800px; margin: auto; } .preview { width: 64px; height: 80px; float: left; margin-right: 10px; } .preview img { width: 100% } .preview p { text-align: center; }</style></head><body><div class="wrap"><h1>' .. status .. '&nbsp;love.test</h1><ul class="summary">'
local html = '<html><head><style>* { font-family: monospace; margin: 0; font-size: 11px; padding: 0; } body { margin: 50px; } h1 { padding-bottom: 10px; font-size: 13px; } h2 { padding: 20px 0 10px 0; font-size: 12px; } .summary { list-style: none; margin: 0; padding: 0; } .summary li { float: left; background: #eee; padding: 5px; margin-right: 10px; } table { background: #eee; margin-top: 10px; width: 100%; max-width: 800px; border-collapse: collapse } table thead { background: #ddd; } table th, table td { padding: 2px; } tr.red { color: red } .wrap { max-width: 800px; margin: auto; } .preview { width: 64px; height: 80px; float: left; margin-right: 10px; } .preview img { width: 100%; image-rendering: pixelated; } .preview p { text-align: center; }</style></head><body><div class="wrap"><h1>' .. status .. '&nbsp;love.test</h1><ul class="summary">'
html = html ..
'<li>🟢&nbsp;' .. tostring(self.totals[1]) .. ' Tests</li>' ..
'<li>🔴&nbsp;' .. tostring(self.totals[2]) .. ' Failures</li>' ..
Expand All @@ -178,7 +178,7 @@ TestSuite = {
self.module:log('grey', '\nFINISHED - ' .. finaltime .. 's\n')
local failedcol = '\27[31m'
if self.totals[2] == 0 then failedcol = '\27[37m' end
self.module:log('green', tostring(self.totals[1]) .. ' PASSED' .. ' || ' .. failedcol .. tostring(self.totals[2]) .. ' FAILED || \27[37m' .. tostring(self.totals[3]) .. ' SKIPPED')
self.module:log('green', tostring(self.totals[1]) .. ' PASSED' .. ' || ' .. failedcol .. tostring(self.totals[2]) .. ' FAILED || \27[37m' .. tostring(self.totals[3]) .. ' SKIPPED\27[0m')

end

Expand Down
2 changes: 2 additions & 0 deletions testing/conf.lua
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
function love.conf(t)
print("love.conf")
t.identity = 'love-test'
t.console = true
t.window.name = 'love.test'
t.window.width = 360
t.window.height = 240
t.window.resizable = true
t.window.depth = true
t.window.stencil = true
t.window.usedpiscale = false -- needed for Android
t.renderers = {"opengl"}
end

Expand Down
4 changes: 3 additions & 1 deletion testing/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,11 @@ love.load = function(args)
end

-- mount for output later
if love.filesystem.mountFullPath then
if love.filesystem.mountFullPath and love.system.getOS() ~= "Android" then
love.filesystem.mountFullPath(love.filesystem.getSource() .. "/output", "tempoutput", "readwrite")
end
love.filesystem.createDirectory("tempoutput/actual")
love.filesystem.createDirectory("tempoutput/expected")

-- get all args with any comma lists split out as seperate
local arglist = {}
Expand Down
Binary file added testing/resources/love.etc.ktx
Binary file not shown.
12 changes: 11 additions & 1 deletion testing/tests/filesystem.lua
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,11 @@ end

-- love.filesystem.mountFullPath
love.test.filesystem.mountFullPath = function(test)
if love.system.getOS() == 'Android' then
test:skipTest('getSource() mounting is not supported for .love files')
return
end

-- mount something in the working directory
local mount = love.filesystem.mountFullPath(love.filesystem.getSource() .. '/tests', 'tests', 'read')
test:assertTrue(mount, 'check can mount')
Expand All @@ -375,6 +380,11 @@ end

-- love.filesystem.unmountFullPath
love.test.filesystem.unmountFullPath = function(test)
if love.system.getOS() == 'Android' then
test:skipTest('getSource() mounting is not supported for .love files')
return
end

-- try unmounting something we never mounted
local unmount1 = love.filesystem.unmountFullPath(love.filesystem.getSource() .. '/faker')
test:assertFalse(unmount1, 'check not mounted to start with')
Expand All @@ -393,7 +403,7 @@ love.test.filesystem.mountCommonPath = function(test)
local mount3 = love.filesystem.mountCommonPath('userhome', 'userhome', 'readwrite')
local mount4 = love.filesystem.mountCommonPath('userappdata', 'userappdata', 'readwrite')
-- userdesktop isnt valid on linux
if love.system.getOS() ~= 'Linux' then
if love.system.getOS() ~= 'Linux' and love.system.getOS() ~= 'Android' then
local mount5 = love.filesystem.mountCommonPath('userdesktop', 'userdesktop', 'readwrite')
test:assertTrue(mount5, 'check mount userdesktop')
end
Expand Down
15 changes: 12 additions & 3 deletions testing/tests/graphics.lua
Original file line number Diff line number Diff line change
Expand Up @@ -374,9 +374,18 @@ love.test.graphics.Image = function(test)
-- check image properties
test:assertFalse(image:isCompressed(), 'check not compressed')
test:assertFalse(image:isFormatLinear(), 'check not linear')
local cimage = love.graphics.newImage('resources/love.dxt1')
test:assertObject(cimage)
test:assertTrue(cimage:isCompressed(), 'check is compressed')

-- check compressed
local supportedimgs = love.graphics.getTextureFormats({canvas = false})
if supportedimgs['DXT1'] then
local cimage = love.graphics.newImage('resources/love.dxt1')
test:assertObject(cimage)
test:assertTrue(cimage:isCompressed(), 'check is compressed')
elseif supportedimgs['ETC1'] then
local cimage = love.graphics.newImage('resources/love.etc.ktx')
test:assertObject(cimage)
test:assertTrue(cimage:isCompressed(), 'check is compressed')
end

-- check pixel replacement
local rimage = love.image.newImageData('resources/loveinv.png')
Expand Down
42 changes: 38 additions & 4 deletions testing/tests/window.lua
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,10 @@ end
-- @NOTE could prob add more checks on the flags here based on conf.lua
love.test.window.getMode = function(test)
local w, h, flags = love.window.getMode()
test:assertEquals(360, w, 'check w')
test:assertEquals(240, h, 'check h')
if love._os ~= 'iOS' and love._os ~= 'Android' then
test:assertEquals(360, w, 'check w')
test:assertEquals(240, h, 'check h')
end
test:assertFalse(flags["fullscreen"], 'check fullscreen')
end

Expand Down Expand Up @@ -164,6 +166,11 @@ end

-- love.window.isMaximized
love.test.window.isMaximized = function(test)
if love.system.getOS() == 'Android' or love.system.getOS() == 'iOS' then
test:skipTest('undefined/unavailable in mobile')
return
end

test:assertFalse(love.window.isMaximized(), 'check window not maximized')
love.window.maximize()
test:waitFrames(10)
Expand All @@ -175,6 +182,11 @@ end

-- love.window.isMinimized
love.test.window.isMinimized = function(test)
if love.system.getOS() == 'Android' or love.system.getOS() == 'iOS' then
test:skipTest('undefined/unavailable in mobile')
return
end

-- check not minimized to start
test:assertFalse(love.window.isMinimized(), 'check window not minimized')
-- try to minimize
Expand Down Expand Up @@ -204,6 +216,11 @@ end

-- love.window.maximize
love.test.window.maximize = function(test)
if love.system.getOS() == 'Android' or love.system.getOS() == 'iOS' then
test:skipTest('undefined/unavailable in mobile')
return
end

test:assertFalse(love.window.isMaximized(), 'check window not maximized')
-- check maximizing is set
love.window.maximize()
Expand All @@ -216,6 +233,11 @@ end

-- love.window.minimize
love.test.window.minimize = function(test)
if love.system.getOS() == 'Android' or love.system.getOS() == 'iOS' then
test:skipTest('undefined/unavailable in mobile')
return
end

test:assertFalse(love.window.isMinimized(), 'check window not minimized')
-- check minimizing is set
love.window.minimize()
Expand All @@ -234,6 +256,11 @@ end

-- love.window.restore
love.test.window.restore = function(test)
if love.system.getOS() == 'Android' or love.system.getOS() == 'iOS' then
test:skipTest('undefined/unavailable in mobile')
return
end

-- check minimized to start
love.window.minimize()
test:waitFrames(10)
Expand Down Expand Up @@ -286,8 +313,10 @@ love.test.window.setMode = function(test)
})
-- check what we set is returned
local width, height, flags = love.window.getMode()
test:assertEquals(512, width, 'check window w match')
test:assertEquals(512, height, 'check window h match')
if love.system.getOS() ~= 'iOS' and love.system.getOS() ~= 'Android' then
test:assertEquals(512, width, 'check window w match')
test:assertEquals(512, height, 'check window h match')
end
test:assertFalse(flags["fullscreen"], 'check window not fullscreen')
test:assertFalse(flags["resizable"], 'check window not resizeable')
love.window.setMode(360, 240, {
Expand All @@ -298,6 +327,11 @@ end

-- love.window.setPosition
love.test.window.setPosition = function(test)
if love.system.getOS() == 'Android' or love.system.getOS() == 'iOS' then
test:skipTest('undefined/unavailable in mobile')
return
end

-- check position is returned
love.window.setPosition(100, 100, 1)
test:waitFrames(10)
Expand Down