finish graphics module + HTML image comparison

- added mostly all graphics draw tests
- added a basic set of "expected" images (generated from successful tests)
- HTML output now shows the expected vs actual generated images for each of the graphics tests applicable
This commit is contained in:
ell
2023-10-09 22:32:41 +01:00
parent add23a4ab0
commit f477b8085f
49 changed files with 366 additions and 32 deletions
+27 -6
View File
@@ -4,6 +4,7 @@ on: [push, pull_request]
jobs:
linux-os:
runs-on: ubuntu-20.04
timeout-minutes: 60
steps:
- name: Update APT
run: sudo apt-get update
@@ -50,9 +51,12 @@ jobs:
name: love-x86_64-AppImage-debug
path: love-${{ github.sha }}.AppImage-debug.tar.gz
- name: Make Runnable
run: chmod a+x love-${{ github.sha }}.AppImage
run: |
chmod a+x love-${{ github.sha }}.AppImage
echo "ready to run"
ls
- name: Run All Tests
run: xvfb-run ./love-${{ github.sha }}.AppImage testing
run: xvfb-run ./love-${{ github.sha }}.AppImage ./testing/main.lua
- name: Love Test Report
uses: ellraiser/love-test-report@main
with:
@@ -61,6 +65,7 @@ jobs:
path: testing/output/lovetest_runAllTests.md
windows-os:
runs-on: windows-latest
timeout-minutes: 60
strategy:
matrix:
platform: [Win32, x64, ARM64]
@@ -214,9 +219,21 @@ jobs:
uses: actions/upload-artifact@v3
with:
name: love-windows-${{ steps.vars.outputs.arch }}${{ steps.vars.outputs.compatname }}-dbg
path: pdb/Release/*.pdb
path: pdb/Release/*.pdb
- name: Install Scream
shell: powershell
run: |
Start-Service audio*
Invoke-WebRequest https://github.com/duncanthrax/scream/releases/download/3.6/Scream3.6.zip -OutFile C:\Scream3.6.zip
Extract-7Zip -Path C:\Scream3.6.zip -DestinationPath C:\Scream
$cert = (Get-AuthenticodeSignature C:\Scream\Install\driver\Scream.sys).SignerCertificate
$store = [System.Security.Cryptography.X509Certificates.X509Store]::new("TrustedPublisher", "LocalMachine")
$store.Open("ReadWrite")
$store.Add($cert)
$store.Close()
cd C:\Scream\Install\driver
C:\Scream\Install\helpers\devcon install Scream.inf *Scream
- name: Install Mesa
if: steps.vars.outputs.arch != 'ARM64'
run: |
curl -L --output mesa.7z --url https://github.com/pal1000/mesa-dist-win/releases/download/23.2.1/mesa3d-23.2.1-release-msvc.7z
7z x mesa.7z -o*
@@ -226,7 +243,9 @@ jobs:
run: cmake --build build --config Release --target install
- name: Run All Tests
if: steps.vars.outputs.arch != 'ARM64'
run: powershell.exe install/lovec.exe testing
run: |
dir
powershell.exe ./install/lovec.exe ./testing/main.lua
- name: Love Test Report
if: steps.vars.outputs.arch != 'ARM64'
uses: ellraiser/love-test-report@main
@@ -236,6 +255,7 @@ jobs:
path: testing/output/lovetest_runAllTests.md
macOS:
runs-on: macos-latest
timeout-minutes: 60
steps:
- name: Checkout
uses: actions/checkout@v3
@@ -263,7 +283,7 @@ jobs:
name: love-macos
path: love-macos.zip
- name: Run All Tests
run: love-macos/love.app/Contents/MacOS/love testing
run: love-macos/love.app/Contents/MacOS/love testing/main.lua
- name: Love Test Report
uses: ellraiser/love-test-report@main
with:
@@ -272,6 +292,7 @@ jobs:
path: testing/output/lovetest_runAllTests.md
iOS-Simulator:
runs-on: macos-latest
timeout-minutes: 60
steps:
- name: Checkout
uses: actions/checkout@v3
+1
View File
@@ -72,3 +72,4 @@ stamp-h1
/testing/output/*.xml
/testing/output/*.html
/testing/output/*.md
/testing/output/actual/*.png
+32 -6
View File
@@ -33,9 +33,13 @@ TestMethod = {
blue = {0, 0, 1, 1},
bluefade = {0, 0, 1, 0.5},
yellow = {1, 1, 0, 1},
pink = {1, 0, 1, 1},
black = {0, 0, 0, 1},
white = {1, 1, 1, 1}
white = {1, 1, 1, 1},
lovepink = {214/255, 86/255, 151/255, 1},
loveblue = {83/255, 168/255, 220/255, 1}
},
imgs = 1,
delay = 0,
delayed = false
}
@@ -82,6 +86,10 @@ TestMethod = {
tg = math.floor((tg*10)+0.5)/10
tb = math.floor((tb*10)+0.5)/10
ta = math.floor((ta*10)+0.5)/10
col[1] = math.floor((col[1]*10)+0.5)/10
col[2] = math.floor((col[2]*10)+0.5)/10
col[3] = math.floor((col[3]*10)+0.5)/10
col[4] = math.floor((col[4]*10)+0.5)/10
-- @TODO add some sort pixel tolerance to the coords
self:assertEquals(col[1], tr, 'check pixel r for ' .. i .. ' at ' .. compare_id .. '(' .. label .. ')')
self:assertEquals(col[2], tg, 'check pixel g for ' .. i .. ' at ' .. compare_id .. '(' .. label .. ')')
@@ -227,6 +235,14 @@ TestMethod = {
end,
exportImg = function(self, imgdata)
local path = 'tempoutput/actual/love.test.graphics.' ..
self.method .. '-' .. tostring(self.imgs) .. '.png'
imgdata:encode('png', path)
self.imgs = self.imgs + 1
end,
-- @method - TestMethod:skipTest()
-- @desc - used to mark this test as skipped for a specific reason
-- @param {string} reason - reason why method is being skipped
@@ -356,11 +372,21 @@ TestMethod = {
-- unused currently, adds a preview image for certain graphics methods to the output
local preview = ''
-- if self.testmodule.module == 'graphics' then
-- local filename = 'love_test_graphics_rectangle'
-- preview = '<div class="preview">' .. '<img src="' .. filename .. '_expected.png"/><p>Expected</p></div>' ..
-- '<div class="preview"><img src="' .. filename .. '_actual.png"/><p>Actual</p></div>'
-- end
if self.testmodule.module == 'graphics' then
local filename = 'love.test.graphics.' .. self.method
if love.filesystem.openFile('tempoutput/actual/' .. filename .. '-1.png', 'r') then
preview = '<div class="preview">' .. '<img src="expected/' .. filename .. '-1.png"/><p>Expected</p></div>' ..
'<div class="preview">' .. '<img src="actual/' .. filename .. '-1.png"/><p>Actual</p></div>'
end
if love.filesystem.openFile('tempoutput/actual/' .. filename .. '-2.png', 'r') then
preview = preview .. '<div class="preview">' .. '<img src="expected/' .. filename .. '-2.png"/><p>Expected</p></div>' ..
'<div class="preview">' .. '<img src="actual/' .. filename .. '-2.png"/><p>Actual</p></div>'
end
if love.filesystem.openFile('tempoutput/actual/' .. filename .. '-3.png', 'r') then
preview = preview .. '<div class="preview">' .. '<img src="expected/' .. filename .. '-3.png"/><p>Expected</p></div>' ..
'<div class="preview">' .. '<img src="actual/' .. filename .. '-3.png"/><p>Actual</p></div>'
end
end
-- append HTML for the test class result
local status = '🔴'
+1 -1
View File
@@ -88,7 +88,7 @@ TestModule = {
if self.failed == 0 then status = '🟢' end
-- add md row to main output
love.test.mdrows = love.test.mdrows .. '| ' .. status ..
' love.' .. self.module ..
' ' .. self.module ..
' | ' .. tostring(self.passed) ..
' | ' .. tostring(self.failed) ..
' | ' .. tostring(self.skipped) ..
-2
View File
@@ -187,8 +187,6 @@ TestSuite = {
'<li>🟡&nbsp;' .. tostring(self.totals[3]) .. ' Skipped</li>' ..
'<li>' .. finaltime .. 's</li></ul><br/><br/>'
-- @TODO use mountFullPath to write output to src?
love.filesystem.mountFullPath(love.filesystem.getSource() .. "/output", "tempoutput", "readwrite")
love.filesystem.write('tempoutput/' .. self.output .. '.xml', xml .. self.xml .. '</testsuites>')
love.filesystem.write('tempoutput/' .. self.output .. '.html', html .. self.html .. '</div></body></html>')
love.filesystem.write('tempoutput/' .. self.output .. '.md', md)
+3
View File
@@ -53,6 +53,9 @@ love.load = function(args)
end
end
-- mount for output later
love.filesystem.mountFullPath(love.filesystem.getSource() .. "/output", "tempoutput", "readwrite")
-- get all args with any comma lists split out as seperate
local arglist = {}
for a=1,#args do
+2
View File
@@ -0,0 +1,2 @@
# Actual Graphics Output
The images generated by the tests
Binary file not shown.

After

Width:  |  Height:  |  Size: 89 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 245 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 204 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 223 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 212 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 84 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 221 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 386 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 185 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 91 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 139 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 90 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 111 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 154 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 90 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 154 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 196 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 91 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 92 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 103 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 89 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 91 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 123 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 84 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 128 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 99 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 106 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 122 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 102 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 118 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 89 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 84 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 107 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 128 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 98 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 101 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 93 B

+2
View File
@@ -0,0 +1,2 @@
# Expected Graphics Output
The images expected by the tests
Binary file not shown.

After

Width:  |  Height:  |  Size: 680 B

+295 -15
View File
@@ -10,31 +10,159 @@
-- love.graphics.arc
love.test.graphics.arc = function(test)
test:skipTest('test class needs writing')
-- draw some arcs using pi format
local canvas = love.graphics.newCanvas(32, 32)
love.graphics.setCanvas(canvas)
love.graphics.clear(0, 0, 0, 1)
love.graphics.setColor(1, 1, 1, 1)
love.graphics.arc('line', "pie", 16, 16, 16, 0 * (math.pi/180), 360 * (math.pi/180), 10)
love.graphics.arc('fill', "pie", 16, 16, 16, 270 * (math.pi/180), 45 * (math.pi/180), 10)
love.graphics.setColor(1, 0, 0, 1)
love.graphics.arc('line', "pie", 16, 16, 16, 0 * (math.pi/180), 90 * (math.pi/180), 10)
love.graphics.setColor(1, 1, 0, 1)
love.graphics.arc('line', "pie", 16, 16, 16, 180 * (math.pi/180), 135 * (math.pi/180), 10)
love.graphics.setColor(1, 1, 1, 1)
love.graphics.setCanvas()
local imgdata1 = love.graphics.readbackTexture(canvas, {16, 0, 0, 0, 16, 16})
test:assertPixels(imgdata1, {
white = {{11,0},{20,0},{0,13},{0,14},{31,13},{31,14},{15,14}},
black = {{16,14},{16,16},{30,14},{30,16}},
yellow = {{15,15},{15,16},{16,15},{0,15},{4,27},{5,26},{14,17}},
red = {{15,17},{15,31},{17,15},{31,15},{28,26},{27,27}}
}, 'arc pi')
-- draw some arcs with open format
love.graphics.setCanvas(canvas)
love.graphics.clear(0, 0, 0, 1)
love.graphics.setColor(1, 1, 1, 1)
love.graphics.arc('line', "open", 16, 16, 16, 0 * (math.pi/180), 315 * (math.pi/180), 10)
love.graphics.setColor(1, 0, 0, 1)
love.graphics.arc('fill', "open", 16, 16, 16, 0 * (math.pi/180), 180 * (math.pi/180), 10)
love.graphics.setColor(1, 1, 0, 1)
love.graphics.arc('fill', "open", 16, 16, 16, 180 * (math.pi/180), 90 * (math.pi/180), 10)
love.graphics.setColor(1, 1, 1, 1)
love.graphics.setCanvas()
local imgdata2 = love.graphics.readbackTexture(canvas, {16, 0, 0, 0, 16, 16})
test:assertPixels(imgdata2, {
white = {{11,0},{20,0},{26,4},{5,4},{0,15},{19,31},{31,19}},
black = {{27,5},{27,4},{26,5},{1,15},{31,15}},
yellow = {{0,17},{0,19},{12,31},{14,31},{6,23},{7,24}},
red = {{0,16},{31,16},{31,18},{30,21},{18,31},{15,16},{16,16}}
}, 'arc open')
-- draw some arcs with closed format
love.graphics.setCanvas(canvas)
love.graphics.clear(0, 0, 0, 1)
love.graphics.setColor(1, 1, 1, 1)
love.graphics.arc('line', "closed", 16, 16, 16, 0 * (math.pi/180), 315 * (math.pi/180), 10)
love.graphics.setColor(1, 0, 0, 1)
love.graphics.arc('fill', "closed", 16, 16, 16, 0 * (math.pi/180), 180 * (math.pi/180), 10)
love.graphics.setColor(1, 1, 0, 1)
love.graphics.arc('line', "closed", 16, 16, 16, 180 * (math.pi/180), 90 * (math.pi/180), 10)
love.graphics.setColor(1, 1, 1, 1)
love.graphics.setCanvas()
local imgdata3 = love.graphics.readbackTexture(canvas, {16, 0, 0, 0, 16, 16})
test:assertPixels(imgdata3, {
white = {{11,0},{20,0},{26,4},{5,4},{0,15},{19,31},{31,19}},
yellow = {{0,17},{0,19},{12,31},{14,31}},
red = {{31,16},{31,18},{30,21},{18,31},{15,16},{16,16}}
}, 'arc open')
test:exportImg(imgdata1)
test:exportImg(imgdata2)
test:exportImg(imgdata3)
end
-- love.graphics.circle
love.test.graphics.circle = function(test)
test:skipTest('test class needs writing')
-- draw some circles
local canvas = love.graphics.newCanvas(32, 32)
love.graphics.setCanvas(canvas)
love.graphics.clear(0, 0, 0, 1)
love.graphics.setColor(1, 1, 1, 1)
love.graphics.circle('fill', 16, 16, 16)
love.graphics.setColor(1, 0, 0, 1)
love.graphics.circle('line', 16, 16, 16)
love.graphics.setColor(1, 1, 0, 1)
love.graphics.circle('fill', 16, 16, 8)
love.graphics.setColor(0, 1, 0, 1)
love.graphics.circle('fill', 16, 16, 4)
love.graphics.setColor(1, 1, 1, 1)
love.graphics.setCanvas()
local imgdata = love.graphics.readbackTexture(canvas, {16, 0, 0, 0, 16, 16})
test:assertPixels(imgdata, {
white = {{13,8},{18,8},{23,13},{23,18}},
green = {
{15,12},{16,12},{13,13},{18,13},{12,15},{12,16},{13,18},{18,18},
{15,19},{16,19},{19,15},{19,16}
},
black = {{10,0},{21,0},{0,10},{0,21},{31,10},{31,21},{10,31},{21,31}},
yellow = {
{11,10},{10,11},{8,14},{8,17},{10,20},{11,21},{14,23},{17,23},{20,21},
{21,20},{23,17},{23,14},{20,10},{21,11},{17,8},{14,8}
},
red = {{11,0},{20,0},{11,31},{20,31},{0,11},{0,20},{31,20},{31,11}}
}, 'circle')
test:exportImg(imgdata)
end
-- love.graphics.clear
love.test.graphics.clear = function(test)
test:skipTest('test class needs writing')
local canvas = love.graphics.newCanvas(16, 16)
love.graphics.setCanvas(canvas)
love.graphics.clear(0, 0, 0, 1)
love.graphics.clear(1, 1, 0, 1)
love.graphics.setCanvas()
local imgdata = love.graphics.readbackTexture(canvas, {16, 0, 0, 0, 16, 16})
test:assertPixels(imgdata, {
yellow = {{0,0},{15,0},{0,15},{15,15},{8,8}}
}, 'clear')
test:exportImg(imgdata)
end
-- love.graphics.discard
love.test.graphics.discard = function(test)
test:skipTest('test class needs writing')
test:skipTest('cant test this worked')
-- wrote all this before seeing "on some desktops this may do nothing"
-- leaving in case we need it in future
--local canvas = love.graphics.newCanvas(32, 32)
--love.graphics.setCanvas(canvas)
-- love.graphics.clear(0, 0, 0, 1)
-- love.graphics.draw(Logo.texture, Logo.img, 0, 0)
-- love.graphics.discard(true, true)
--love.graphics.setCanvas()
end
-- love.graphics.draw
love.test.graphics.draw = function(test)
test:skipTest('test class needs writing')
local canvas1 = love.graphics.newCanvas(32, 32)
local canvas2 = love.graphics.newCanvas(32, 32)
local transform = love.math.newTransform( )
transform:translate(16, 0)
transform:scale(0.5, 0.5)
love.graphics.setCanvas(canvas1)
love.graphics.clear(0, 0, 0, 1)
-- img, offset
love.graphics.draw(Logo.texture, Logo.img, 0, 0, 0, 1, 1, 16, 16)
love.graphics.setCanvas()
love.graphics.setCanvas(canvas2)
love.graphics.clear(1, 0, 0, 1)
-- canvas, scale, shear, transform obj
love.graphics.draw(canvas1, 0, 0, 0, 0.5, 0.5, 0, 0, 2, 2)
love.graphics.draw(canvas1, 0, 16, 0, 0.5, 0.5)
love.graphics.draw(canvas1, 16, 16, 0, 0.5, 0.5)
love.graphics.draw(canvas1, transform)
love.graphics.setCanvas()
local imgdata = love.graphics.readbackTexture(canvas2, {16, 0, 0, 0, 16, 16})
test:assertPixels(imgdata, {
lovepink = {{23,3},{23,19},{7,19},{0,0},{16,0},{0,16},{16,16}},
loveblue = {{0,31},{15,17},{15,31},{16,31},{31,17},{31,31},{16,15},{31,15}},
white = {{15, 15},{6,19},{8,19},{22,19},{24,19},{22,3},{24,3}},
red = {{0,1},{1,0},{15,0},{15,7},{0,15},{7,15}}
}, 'drawing')
test:exportImg(imgdata)
end
@@ -46,37 +174,115 @@ end
-- love.graphics.drawLayer
love.test.graphics.drawLayer = function(test)
test:skipTest('test class needs writing')
local image = love.graphics.newArrayImage({
'resources/love.png', 'resources/loveinv.png',
'resources/love.png', 'resources/loveinv.png'
})
local canvas = love.graphics.newCanvas(64, 64)
love.graphics.setCanvas(canvas)
love.graphics.clear(0, 0, 0, 1)
love.graphics.drawLayer(image, 1, 0, 0, 0, 1, 1)
love.graphics.drawLayer(image, 2, 32, 0, 0, 0.5, 0.5)
love.graphics.drawLayer(image, 4, 0, 32, 0, 0.5, 0.5)
love.graphics.drawLayer(image, 3, 32, 32, 0, 2, 2, 16, 16)
love.graphics.setCanvas()
local imgdata = love.graphics.readbackTexture(canvas, {16, 0, 0, 0, 16, 16})
test:assertPixels(imgdata, {
lovepink = {{30,2},{33,2},{2,30},{2,33},{4,60},{4,63},{60,4},{63,4},{31,23},{32,23}},
loveblue = {{14,33},{17,33},{46,1},{49,1},{1,46},{1,49},{33,14},{33,17}},
black = {{0,0},{63,0},{0,63},{39,6},{40,6},{6,39},{6,40},{6,55},{55,6}},
white = {{46,11},{48,11},{14,43},{16,43},{30,23},{33,23},{34,54},{53,40},{63,63}}
}, 'draw layer')
test:exportImg(imgdata)
end
-- love.graphics.ellipse
love.test.graphics.ellipse = function(test)
test:skipTest('test class needs writing')
local canvas = love.graphics.newCanvas(32, 32)
love.graphics.setCanvas(canvas)
love.graphics.clear(0, 0, 0, 1)
love.graphics.setColor(1, 0, 0, 1)
love.graphics.ellipse('fill', 16, 16, 16, 8)
love.graphics.setColor(1, 1, 0, 1)
love.graphics.ellipse('fill', 24, 24, 10, 24)
love.graphics.setColor(1, 0, 1, 1)
love.graphics.ellipse('fill', 16, 0, 8, 16)
love.graphics.setColor(1, 1, 1, 1)
love.graphics.setCanvas()
local imgdata = love.graphics.readbackTexture(canvas, {16, 0, 0, 0, 16, 16})
test:assertPixels(imgdata, {
red = {{0,14},{0,17},{7,9},{7,22},{14,15},{14,16}},
pink = {{15,15},{16,15},{8,0},{8,4},{23,0},{23,4},{13,14},{18,14}},
yellow = {{24,0},{25,0},{14,17},{14,30},{15,31},{31,8}}
}, 'ellipses')
test:exportImg(imgdata)
end
-- love.graphics.flushBatch
love.test.graphics.flushBatch = function(test)
test:skipTest('test class needs writing')
test:skipTest('not sure can be tested as used internally')
end
-- love.graphics.line
love.test.graphics.line = function(test)
test:skipTest('test class needs writing')
local canvas = love.graphics.newCanvas(16, 16)
love.graphics.setCanvas(canvas)
love.graphics.clear(0, 0, 0, 1)
love.graphics.setColor(1, 0, 0, 1)
love.graphics.line(1,1,16,1,16,16,1,16,1,1)
love.graphics.setColor(1, 1, 0, 1)
love.graphics.line({0,0,8,8,16,0,8,8,16,16,8,8,0,16})
love.graphics.setColor(1, 1, 1, 1)
love.graphics.setCanvas()
local imgdata = love.graphics.readbackTexture(canvas, {16, 0, 0, 0, 16, 16})
test:assertPixels(imgdata, {
yellow = {{0,0},{15,0},{0,15},{15,15},{7,7},{8,7},{8,7},{8,8}},
red = {{1,0},{14,0},{0,1},{0,14},{15,1},{15,14},{1,15},{14,15}}
}, 'lines')
test:exportImg(imgdata)
end
-- love.graphics.points
love.test.graphics.points = function(test)
test:skipTest('test class needs writing')
local canvas = love.graphics.newCanvas(16, 16)
love.graphics.setCanvas(canvas)
love.graphics.clear(0, 0, 0, 1)
love.graphics.setColor(1, 0, 0, 1)
love.graphics.points(1,1,16,1,16,16,1,16,1,1)
love.graphics.setColor(1, 1, 0, 1)
love.graphics.points({2,2,8,8,15,2,8,9,15,15,9,9,2,15,9,8})
love.graphics.setColor(1, 1, 1, 1)
love.graphics.setCanvas()
local imgdata = love.graphics.readbackTexture(canvas, {16, 0, 0, 0, 16, 16})
test:assertPixels(imgdata, {
yellow = {{1,1},{14,1},{1,14},{14,14},{7,7},{8,7},{8,7},{8,8}},
red = {{0,0},{15,0},{15,15},{0,15}}
}, 'points')
test:exportImg(imgdata)
end
-- love.graphics.polygon
love.test.graphics.polygon = function(test)
test:skipTest('test class needs writing')
local canvas = love.graphics.newCanvas(16, 16)
love.graphics.setCanvas(canvas)
love.graphics.clear(0, 0, 0, 1)
love.graphics.setColor(1, 0, 0, 1)
love.graphics.polygon("fill", 1, 1, 4, 5, 8, 10, 16, 2, 7, 3, 5, 16, 16, 16, 1, 8)
love.graphics.setColor(1, 1, 0, 1)
love.graphics.polygon("line", {2, 2, 4, 5, 3, 7, 8, 15, 12, 4, 5, 10})
love.graphics.setColor(1, 1, 1, 1)
love.graphics.setCanvas()
local imgdata = love.graphics.readbackTexture(canvas, {16, 0, 0, 0, 16, 16})
test:assertPixels(imgdata, {
yellow = {{1,0},{1,1},{5,9},{7,14},{8,14},{12,3}},
red = {{2,1},{1,2},{1,7},{5,15},{14,15},{8,8},{14,2},{7,1}}
}, 'polygon')
test:exportImg(imgdata)
end
@@ -88,13 +294,61 @@ end
-- love.graphics.print
love.test.graphics.print = function(test)
test:skipTest('test class needs writing')
love.graphics.setFont(Font)
local canvas = love.graphics.newCanvas(16, 16)
love.graphics.setCanvas(canvas)
love.graphics.clear(0, 0, 0, 1)
love.graphics.setColor(1, 0, 0, 1)
love.graphics.print('love', 0, 3, 0, 1, 1, 0, 0)
love.graphics.setColor(0, 1, 0, 1)
love.graphics.print('ooo', 0, 3, 0, 2, 2, 0, 0)
love.graphics.setColor(0, 0, 1, 1)
love.graphics.print('hello', 0, 3, 90*(math.pi/180), 1, 1, 0, 8)
love.graphics.setColor(1, 1, 1, 1)
love.graphics.setCanvas()
local imgdata = love.graphics.readbackTexture(canvas, {16, 0, 0, 0, 16, 16})
test:assertPixels(imgdata, {
red = {{0,0},{1,0},{1,1},{2,6},{4,4},{7,6},{10,2},{11,5},{14,3},{14,4}},
green = {
{2,1},{2,2},{0,3},{1,3},{1,8},{2,9},{7,10},{8,8},{9,4},{13,3},{14,2},
{13,8},{14,9}
},
blue = {
{4,15},{10,15},{4,12},{6,12},{8,12},{5,9},{7,9},{4,3},{10,3},{8,6},{7,7},
{4,7},{7,13},{8,12}
}
}, 'print')
test:exportImg(imgdata)
end
-- love.graphics.printf
love.test.graphics.printf = function(test)
test:skipTest('test class needs writing')
love.graphics.setFont(Font)
local canvas = love.graphics.newCanvas(32, 32)
love.graphics.setCanvas(canvas)
love.graphics.clear(0, 0, 0, 1)
love.graphics.setColor(1, 0, 0, 1)
love.graphics.printf('love', 0, 0, 8, "left")
love.graphics.setColor(0, 1, 0, 1)
love.graphics.printf('love', 0, 5, 16, "right")
love.graphics.setColor(0, 0, 1, 1)
love.graphics.printf('love', 0, 7, 32, "center")
love.graphics.setColor(1, 1, 1, 1)
love.graphics.setCanvas()
local imgdata = love.graphics.readbackTexture(canvas, {16, 0, 0, 0, 16, 16})
test:assertPixels(imgdata, {
red = {
{1,0},{1,1},{0,3},{2,3},{2,7},{0,9},{3,11},{4,10},{0,15},{4,15},{2,19},
{0,24},{1,23},{3,23},{4,24},{0,26},{1,27},{2,27},{3,27}
},
green = {
{1,2},{0,8},{1,8},{2,8},{4,7},{5,8},{7,8},{8,7},{10,4},{14,4},{11,7},
{12,8},{10,13},{11,12},{13,12},{14,13},{10,15},{11,16}
},
blue = {{6,4},{6,10},{9,7},{10,6},{16,9},{18,9},{21,8},{25,8}}
}, 'printf')
test:exportImg(imgdata)
end
@@ -138,6 +392,8 @@ love.test.graphics.rectangle = function(test)
{9,14},{11,1},{14,1},{11,14},{14,14}
}
}, 'line')
test:exportImg(imgdata1)
test:exportImg(imgdata2)
end
@@ -557,7 +813,8 @@ love.test.graphics.intersectScissor = function(test)
love.graphics.origin()
love.graphics.setScissor(0, 0, 8, 16)
love.graphics.intersectScissor(0, 0, 4, 4)
love.graphics.clear(1, 0, 0, 1)
love.graphics.setColor(1, 0, 0, 1)
love.graphics.rectangle('fill', 0, 0, 16, 16)
love.graphics.setColor(1, 1, 1, 1)
love.graphics.setScissor()
love.graphics.setCanvas()
@@ -566,6 +823,7 @@ love.test.graphics.intersectScissor = function(test)
red = {{0,0},{3,3}},
black ={{4,0},{0,4},{4,4}}
}, 'intersect scissor')
test:exportImg(imgdata)
end
@@ -651,6 +909,7 @@ love.test.graphics.setBlendMode = function(test)
bluefade = {{0,15}}
}, 'blend mode')
love.graphics.setBlendMode('alpha', 'alphamultiply') -- reset
test:exportImg(imgdata)
end
@@ -673,6 +932,7 @@ love.test.graphics.setCanvas = function(test)
test:assertPixels(imgdata, {
red = {{0,0},{15,0},{15,15},{0,15}}
}, 'set canvas')
test:exportImg(imgdata)
end
@@ -704,6 +964,7 @@ love.test.graphics.setColor = function(test)
greenhalf = {{0,2},{5,2},{10,2},{15,2}},
blue = {{0,3},{5,3},{10,3},{15,3}}
}, 'set color')
test:exportImg(imgdata)
end
@@ -729,6 +990,7 @@ love.test.graphics.setColorMask = function(test)
test:assertPixels(imgdata, {
yellow = {{0,0},{0,15},{15,15},{15,0}}
}, 'set color mask')
test:exportImg(imgdata)
end
@@ -780,6 +1042,7 @@ love.test.graphics.setFont = function(test)
{14,2},{12,6}
}
}, 'set font for print')
test:exportImg(imgdata)
end
@@ -827,6 +1090,7 @@ love.test.graphics.setLineJoin = function(test)
yellow = {{8,7}},
blue = {{8,8}}
}, 'set line join')
test:exportImg(imgdata)
end
@@ -852,6 +1116,7 @@ love.test.graphics.setLineStyle = function(test)
red = {{0,0},{7,0},{15,0}},
red07 = {{0,4},{7,4},{15,4}}
}, 'set line style')
test:exportImg(imgdata)
end
@@ -884,6 +1149,7 @@ love.test.graphics.setLineWidth = function(test)
yellow = {{0,3},{0,5},{6,6},{8,6}},
blue = {{0,7},{0,10},{6,15},{9,15}}
}, 'set line width')
test:exportImg(imgdata)
end
@@ -910,7 +1176,8 @@ love.test.graphics.setScissor = function(test)
love.graphics.clear(0, 0, 0, 1)
love.graphics.origin()
love.graphics.setScissor(0, 0, 8, 16)
love.graphics.clear(1, 0, 0, 1)
love.graphics.setColor(1, 0, 0, 1)
love.graphics.rectangle('fill', 0, 0, 16, 16)
love.graphics.setColor(1, 1, 1, 1)
love.graphics.setScissor()
love.graphics.setCanvas()
@@ -919,6 +1186,7 @@ love.test.graphics.setScissor = function(test)
red = {{0,0},{7,0},{0,15},{7,15}},
black ={{8,0},{8,15},{15,0},{15,15}}
}, 'set scissor')
test:exportImg(imgdata)
end
@@ -942,6 +1210,7 @@ love.test.graphics.setShader = function(test)
test:assertPixels(imgdata, {
yellow = {{0,0},{15,0},{0,15},{15,15}},
}, 'check shader set to yellow')
test:exportImg(imgdata)
end
@@ -963,6 +1232,7 @@ love.test.graphics.setStencilTest = function(test)
test:assertPixels(imgdata, {
red = {{6,2},{9,2},{2,6},{2,9},{13,6},{9,6},{6,13},{9,13}}
}, 'check stencil test')
test:exportImg(imgdata)
end
@@ -983,6 +1253,7 @@ love.test.graphics.setWireframe = function(test)
yellow = {{1,14},{14,1},{14,14},{2,2},{13,13}},
black = {{2,13},{13,2}}
}, 'set wireframe')
test:exportImg(imgdata)
end
@@ -1008,6 +1279,7 @@ love.test.graphics.applyTransform = function(test)
love.graphics.setCanvas()
local imgdata = love.graphics.readbackTexture(canvas, {16, 0, 0, 0, 16, 16})
test:assertPixels(imgdata, { red = {{10, 0}} }, 'apply transform 10')
test:exportImg(imgdata)
end
@@ -1044,6 +1316,7 @@ love.test.graphics.origin = function(test)
love.graphics.setCanvas()
local imgdata = love.graphics.readbackTexture(canvas, {16, 0, 0, 0, 16, 16})
test:assertPixels(imgdata, { red = {{0, 0}} }, 'origin check')
test:exportImg(imgdata)
end
@@ -1065,6 +1338,7 @@ love.test.graphics.pop = function(test)
love.graphics.setCanvas()
local imgdata = love.graphics.readbackTexture(canvas, {16, 0, 0, 0, 16, 16})
test:assertPixels(imgdata, { red = {{0, 0}} }, 'pop 1')
test:exportImg(imgdata)
end
@@ -1087,6 +1361,7 @@ love.test.graphics.push = function(test)
love.graphics.setCanvas()
local imgdata = love.graphics.readbackTexture(canvas, {16, 0, 0, 0, 16, 16})
test:assertPixels(imgdata, { red = {{1, 1}} }, 'push 1')
test:exportImg(imgdata)
end
@@ -1108,6 +1383,7 @@ love.test.graphics.replaceTransform = function(test)
love.graphics.setCanvas()
local imgdata = love.graphics.readbackTexture(canvas, {16, 0, 0, 0, 16, 16})
test:assertPixels(imgdata, { red = {{10, 0}} }, 'replace transform 10')
test:exportImg(imgdata)
end
@@ -1126,6 +1402,7 @@ love.test.graphics.rotate = function(test)
love.graphics.setCanvas()
local imgdata = love.graphics.readbackTexture(canvas, {16, 0, 0, 0, 16, 16})
test:assertPixels(imgdata, { red = {{0,0},{3,0},{3,3},{0,3}} }, 'rotate 90')
test:exportImg(imgdata)
end
@@ -1173,6 +1450,8 @@ love.test.graphics.shear = function(test)
love.graphics.setCanvas()
local imgdata2 = love.graphics.readbackTexture(canvas, {16, 0, 0, 0, 16, 16})
test:assertPixels(imgdata2, { red = { {0,1},{0,4},{3,7},{3,10}} }, 'shear y')
test:exportImg(imgdata1)
test:exportImg(imgdata2)
end
@@ -1210,6 +1489,7 @@ love.test.graphics.translate = function(test)
love.graphics.setCanvas()
local imgdata = love.graphics.readbackTexture(canvas, {16, 0, 0, 0, 16, 16})
test:assertPixels(imgdata, { red = {{5,0},{0,5},{5,5},{0,0}} }, 'translate 4x')
test:exportImg(imgdata)
end
+3 -2
View File
@@ -1,16 +1,17 @@
`/Applications/love_12.app/Contents/MacOS/love ./testing`
## TESTSUITE
- [ ] setStencilMode to replace setStencilTest
- [ ] start graphics drawing methods
- [ ] move object methods to respective modules
- [ ] start object methods
- [ ] setStencilMode to replace setStencilTest
## GRAPHICS
Methods that need a actual graphic pixel checks if possible:
- [ ] setDepthMode
- [ ] setFrontFaceWinding
- [ ] setMeshCullMode
- [ ] present
- [ ] drawInstanced
## FUTURE
- [ ] need a platform: format table somewhere for compressed formats (i.e. DXT not supported)