Skip to content

Commit

Permalink
more graphics + some physics tests
Browse files Browse the repository at this point in the history
- added obj tests for graphics.SpriteBatch, and graphics.Video
- added obj tests for physics.World
- added test for setStencilMode and removed deprecated stencil+setStencilTest
- added graphics.drawInstanced
- fixed deprecated physic shape calls (body now added as first param)
  • Loading branch information
ellraiser committed Nov 16, 2023
1 parent 1323bb1 commit 8124804
Show file tree
Hide file tree
Showing 14 changed files with 632 additions and 383 deletions.
2 changes: 1 addition & 1 deletion testing/examples/lovetest_runAllTests.html

Large diffs are not rendered by default.

34 changes: 17 additions & 17 deletions testing/examples/lovetest_runAllTests.md
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
<!-- PASSED 282 || FAILED 1 || SKIPPED 20 || TIME 9.881 -->
<!-- PASSED 285 || FAILED 1 || SKIPPED 15 || TIME 14.670 -->

### Info
**303** tests were completed in **9.881s** with **282** passed, **1** failed, and **20** skipped
**301** tests were completed in **14.670s** with **285** passed, **1** failed, and **15** skipped

Renderer: OpenGL | 4.1 Metal - 76.3 | Apple | Apple M1 Max

### Report
| Module | Pass | Fail | Skip | Time |
| --------------------- | ------ | ------ | ------- | ------ |
| 🟢 audio | 28 | 0 | 0 | 0.857s |
| 🟢 data | 12 | 0 | 0 | 0.139s |
| 🟢 event | 4 | 0 | 2 | 0.010s |
| 🟢 filesystem | 29 | 0 | 2 | 0.068s |
| 🔴 font | 6 | 1 | 0 | 0.015s |
| 🟢 graphics | 99 | 0 | 6 | 0.294s |
| 🟢 image | 5 | 0 | 0 | 0.011s |
| 🟢 math | 20 | 0 | 0 | 0.070s |
| 🟢 physics | 22 | 0 | 6 | 0.071s |
| 🟢 sound | 4 | 0 | 0 | 0.015s |
| 🟢 system | 6 | 0 | 2 | 0.026s |
| 🟢 thread | 5 | 0 | 0 | 0.317s |
| 🟢 timer | 6 | 0 | 0 | 2.021s |
| 🟢 video | 2 | 0 | 0 | 0.012s |
| 🟢 window | 34 | 0 | 2 | 5.955s |
| 🟢 audio | 28 | 0 | 0 | 0.890s |
| 🟢 data | 12 | 0 | 0 | 0.205s |
| 🟢 event | 4 | 0 | 2 | 0.102s |
| 🟢 filesystem | 29 | 0 | 2 | 0.530s |
| 🔴 font | 6 | 1 | 0 | 0.121s |
| 🟢 graphics | 102 | 0 | 3 | 3.232s |
| 🟢 image | 5 | 0 | 0 | 0.086s |
| 🟢 math | 20 | 0 | 0 | 0.339s |
| 🟢 physics | 22 | 0 | 4 | 0.434s |
| 🟢 sound | 4 | 0 | 0 | 0.071s |
| 🟢 system | 6 | 0 | 2 | 0.139s |
| 🟢 thread | 5 | 0 | 0 | 0.376s |
| 🟢 timer | 6 | 0 | 0 | 2.091s |
| 🟢 video | 2 | 0 | 0 | 0.039s |
| 🟢 window | 34 | 0 | 2 | 6.015s |

### Failures
> 🔴 GlyphData
Expand Down
609 changes: 300 additions & 309 deletions testing/examples/lovetest_runAllTests.xml

Large diffs are not rendered by default.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
24 changes: 11 additions & 13 deletions testing/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ This is the status of all module tests currently.
| 🟢 event | 4 | 0 | 2 |
| 🟢 filesystem | 29 | 0 | 2 |
| 🟢 font | 7 | 0 | 0 |
| 🟡 graphics | 99 | 5 | 1 |
| 🟡 graphics | 102 | 2 | 1 |
| 🟢 image | 5 | 0 | 0 |
| 🟢 math | 20 | 0 | 0 |
| 🟡 physics | 22 | 6 | 0 |
| 🟡 physics | 22 | 4 | 0 |
| 🟢 sound | 4 | 0 | 0 |
| 🟢 system | 6 | 0 | 2 |
| 🟢 thread | 5 | 0 | 0 |
Expand Down Expand Up @@ -60,7 +60,7 @@ All results will be printed in the console per method as PASS, FAIL, or SKIP wit

When finished, the following files will be generated in the `/output` directory with a summary of the test results:
- an `XML` file in the style of [JUnit XML](https://www.ibm.com/docs/en/developer-for-zos/14.1?topic=formats-junit-xml-format)
- a `HTML` file that shows any visual test results
- a `HTML` file that shows the report + any visual test results
- a `Markdown` file you can use with [this github action](https://github.com/ellraiser/love-test-report)
> An example of all types of output can be found in the `/examples`
> The visual results of any graphic tests can be found in `/output/actual`
Expand Down Expand Up @@ -110,15 +110,13 @@ For sanity-checking, if it's currently not covered or it's not possible to test
---

## Todo
Things still left to do:
- [ ] physics.Body, physics.Contact, physics.Fixture,
physics.Joint, physics.Shape, physics.World
- [ ] @deprecated physics methods (sasha changes)
- [ ] graphics.Mesh, graphics.ParticleSystem
graphics.SpriteBatch, graphics.Video
- [ ] graphics.drawInstanced
- [ ] @deprecated love.graphics.stencil (replaced by love.graphics.setStencilMode)
- [ ] @deprecated love.graphics.setStencilTest (replaced by love.graphics.setStencilMode)
Test classes that still need to be written:
- [ ] graphics.Mesh
- [ ] graphics.ParticleSystem
- [ ] physics.Body
- [ ] physics.Contact
- [ ] physics.Joint
- [ ] physics.Shape

---

Expand All @@ -129,4 +127,4 @@ Things still left to do:
use in the report output comparisons, so we just need to add a helper method
to the test class to let you just do assertMatching on the imgdata
- [ ] Ability to test loading different combinations of modules
- [ ] Performance tests
- [ ] Performance tests
226 changes: 210 additions & 16 deletions testing/tests/graphics.lua
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,11 @@ love.test.graphics.Canvas = function(test)
test:assertEquals('linear', mode, 'check def minmap filter mode')
test:assertEquals(0, sharpness, 'check def minmap filter sharpness')
local name, version, vendor, device = love.graphics.getRendererInfo()
canvas:setMipmapFilter('nearest', 1)
mode, sharpness = canvas:getMipmapFilter()
test:assertEquals('nearest', mode, 'check changed minmap filter mode')
-- mipmap sharpness wont work on opengl/metal
if string.match(name, 'OpenGL ES') == nil and string.match(name, 'Metal') == nil then
canvas:setMipmapFilter('nearest', 1)
mode, sharpness = canvas:getMipmapFilter()
test:assertEquals('nearest', mode, 'check changed minmap filter mode')
test:assertEquals(1, sharpness, 'check changed minmap filter sharpness')
end
test:assertGreaterEqual(2, canvas:getMipmapCount()) -- docs say no mipmaps should return 1
Expand Down Expand Up @@ -209,10 +210,11 @@ love.test.graphics.Image = function(test)
test:assertEquals(0, sharpness, 'check def minmap filter sharpness')

local name, version, vendor, device = love.graphics.getRendererInfo()
-- mipmap sharpness wont work on opengl/metal
image:setMipmapFilter('nearest', 1)
mode, sharpness = image:getMipmapFilter()
test:assertEquals('nearest', mode, 'check changed minmap filter mode')
if string.match(name, 'OpenGL ES') == nil and string.match(name, 'Metal') == nil then
image:setMipmapFilter('nearest', 1)
mode, sharpness = image:getMipmapFilter()
test:assertEquals('nearest', mode, 'check changed minmap filter mode')
test:assertEquals(1, sharpness, 'check changed minmap filter sharpness')
end
test:assertGreaterEqual(2, image:getMipmapCount()) -- docs say no mipmaps should return 1
Expand Down Expand Up @@ -351,7 +353,133 @@ end

-- SpriteBatch (love.graphics.newSpriteBatch)
love.test.graphics.SpriteBatch = function(test)
test:skipTest('test class needs writing')
-- create batch
local texture1 = love.graphics.newImage('resources/cubemap.png')
local texture2 = love.graphics.newImage('resources/love.png')
local quad1 = love.graphics.newQuad(32, 12, 1, 1, texture2) -- lovepink
local quad2 = love.graphics.newQuad(32, 32, 1, 1, texture2) -- white
local sbatch = love.graphics.newSpriteBatch(texture1, 5000)
test:assertObject(sbatch)
-- check basic props
test:assertEquals(0, sbatch:getCount(), 'check batch size')
test:assertEquals(5000, sbatch:getBufferSize(), 'check batch size')
test:assertEquals(texture1:getWidth(), sbatch:getTexture():getWidth(), 'check texture match w')
test:assertEquals(texture1:getHeight(), sbatch:getTexture():getHeight(), 'check texture match h')
sbatch:setTexture(texture2)
test:assertEquals(texture2:getWidth(), sbatch:getTexture():getWidth(), 'check texture change w')
test:assertEquals(texture2:getHeight(), sbatch:getTexture():getHeight(), 'check texture change h')
local r, g, b, a = sbatch:getColor()
test:assertEquals(1, r, 'check initial color r')
test:assertEquals(1, g, 'check initial color g')
test:assertEquals(1, b, 'check initial color b')
test:assertEquals(1, a, 'check initial color a')
sbatch:setColor(1, 0, 0, 1)
r, g, b, a = sbatch:getColor()
test:assertEquals(1, r, 'check set color r')
test:assertEquals(0, g, 'check set color g')
test:assertEquals(0, b, 'check set color b')
test:assertEquals(1, a, 'check set color a')
-- check adding sprites
local offset_x = 0
local offset_y = 0
local color = 'white'
sbatch:setColor(1, 1, 1, 1)
local sprites = {}
for s=1,4096 do
local spr = sbatch:add(quad1, offset_x, offset_y, 0, 1, 1)
table.insert(sprites, {spr, offset_x, offset_y})
offset_x = offset_x + 1
if s % 64 == 0 then
-- alternate row colors
if color == 'white' then
color = 'red'
sbatch:setColor(1, 0, 0, 1)
else
color = 'white'
sbatch:setColor(1, 1, 1, 1)
end
offset_y = offset_y + 1
offset_x = 0
end
end
test:assertEquals(4096, sbatch:getCount())
-- test drawing and setting
local canvas = love.graphics.newCanvas(64, 64)
love.graphics.setCanvas(canvas)
love.graphics.clear(0, 0, 0, 1)
love.graphics.draw(sbatch, 0, 0)
love.graphics.setCanvas()
local imgdata1 = love.graphics.readbackTexture(canvas, {64, 0, 0, 0, 64, 64})
test:assertPixels(imgdata1, {
lovepink = {{0,0},{63,2},{0,32},{63,32},{63,0},{63,2}}
}, 'sbatch draw normal')
test:exportImg(imgdata1)
-- use set to change some sprites
for s=1,2048 do
sbatch:set(sprites[s][1], quad2, sprites[s][2], sprites[s][3]+1, 0, 1, 1)
end
love.graphics.setCanvas(canvas)
love.graphics.clear(0, 0, 0, 1)
love.graphics.draw(sbatch, 0, 0)
love.graphics.setCanvas()
local imgdata2 = love.graphics.readbackTexture(canvas, {64, 0, 0, 0, 64, 64})
test:assertPixels(imgdata2, {
lovepink = {{0,32},{63,32}},
black = {{0,0},{63,0}},
white = {{0,1},{63,1},{0,31},{63,31}}
}, 'sbatch draw set')
test:exportImg(imgdata2)
-- set drawRange and redraw
sbatch:setDrawRange(1025, 2048)
love.graphics.setCanvas(canvas)
love.graphics.clear(0, 0, 0, 1)
love.graphics.draw(sbatch, 0, 0)
love.graphics.setCanvas()
local imgdata3 = love.graphics.readbackTexture(canvas, {64, 0, 0, 0, 64, 64})
test:assertPixels(imgdata3, {
lovepink = {{0,32},{63,32}},
black = {{0,0},{63,0},{0,48},{63,48}},
white = {{0,17},{63,17},{0,31},{63,31}}
}, 'sbatch draw drawrange')
test:exportImg(imgdata3)
-- clear and redraw
sbatch:clear()
love.graphics.setCanvas(canvas)
love.graphics.clear(0, 0, 0, 1)
love.graphics.draw(sbatch, 0, 0)
love.graphics.setCanvas()
local imgdata4 = love.graphics.readbackTexture(canvas, {64, 0, 0, 0, 64, 64})
test:assertPixels(imgdata4, {
black = {{0,0},{63,0},{0,32},{63,32},{0,63},{63,63}},
}, 'sbatch draw clear')
test:exportImg(imgdata4)
-- array texture sbatch
local texture3 = love.graphics.newArrayImage({
'resources/love.png',
'resources/loveinv.png'
})
local asbatch = love.graphics.newSpriteBatch(texture3, 4096)
local quad3 = love.graphics.newQuad(32, 52, 1, 1, texture3) -- loveblue
sprites = {}
for s=1,4096 do
local spr = asbatch:addLayer(1, quad3, 0, s, math.floor(s/64), 1, 1)
table.insert(sprites, {spr, s, math.floor(s/64)})
end
test:assertEquals(4096, asbatch:getCount(), 'check max batch size applies')
for s=1,2048 do
asbatch:setLayer(sprites[s][1], 2, sprites[s][2], sprites[s][3], 0, 1, 1)
end
love.graphics.setCanvas(canvas)
love.graphics.clear(0, 0, 0, 1)
love.graphics.draw(asbatch, 0, 0)
love.graphics.setCanvas()
local imgdata5 = love.graphics.readbackTexture(canvas, {64, 0, 0, 0, 64, 64})
test:assertPixels(imgdata5, {
loveblue = {{31,2},{63,2},{3,30},{3,33},{16,47},{63,47}},
lovepink = {{17,48},{63,48},{31,61},{63,61}},
black = {{0,0},{63,0},{63,63},{63,0},{30,2},{30,61}},
}, 'sbatch draw layers')
test:exportImg(imgdata5)
end


Expand Down Expand Up @@ -396,7 +524,54 @@ end

-- Video (love.graphics.newVideo)
love.test.graphics.Video = function(test)
test:skipTest('test class needs writing')
-- create video
local video = love.graphics.newVideo('resources/sample.ogv')
test:assertObject(video)
-- check basic props
local w, h = video:getDimensions()
test:assertEquals(496, w, 'check vid dim w')
test:assertEquals(502, h, 'check vid dim h')
test:assertEquals(w, video:getWidth(), 'check vid width match')
test:assertEquals(h, video:getHeight(), 'check vid height match')
local min, mag, ani = video:getFilter()
test:assertEquals('nearest', min, 'check def filter min')
test:assertEquals('nearest', mag, 'check def filter mag')
test:assertEquals(1, ani, 'check def filter ani')
video:setFilter('linear', 'linear', 2)
min, mag, ani = video:getFilter()
test:assertEquals('linear', min, 'check changed filter min')
test:assertEquals('linear', mag, 'check changed filter mag')
test:assertEquals(2, ani, 'check changed filter ani')
test:assertEquals(false, video:isPlaying(), 'check paused by default')
test:assertEquals(0, video:tell(), 'check 0:00 by default')
-- covered by their own obj tests in video but check returns obj
local source = video:getSource()
test:assertObject(source)
local stream = video:getStream()
test:assertObject(stream)
-- check playing / pausing / seeking
video:play()
test:waitFrames(60)
video:pause()
test:assertEquals(1, math.ceil(video:tell()), 'check video playing for 1s')
video:seek(0.2)
test:assertEquals(0.2, video:tell(), 'check video seeking')
video:rewind()
test:assertEquals(0, video:tell(), 'check video rewind')
video:setFilter('nearest', 'nearest', 1)
video:play()
-- check actuall drawing with the vid
local canvas = love.graphics.newCanvas(500, 500)
love.graphics.setCanvas(canvas)
love.graphics.clear(1, 0, 0, 1)
love.graphics.draw(video, 0, 0)
love.graphics.setCanvas()
local imgdata = love.graphics.readbackTexture(canvas, {500, 0, 0, 0, 500, 500})
test:assertPixels(imgdata, {
black = {{0,0},{495,0},{495,499},{0,499}},
red = {{499,0},{499,499}}
}, 'video draw')
test:exportImg(imgdata)
end


Expand Down Expand Up @@ -560,7 +735,27 @@ end

-- love.graphics.drawInstanced
love.test.graphics.drawInstanced = function(test)
test:skipTest('test class needs writing')
local image = love.graphics.newImage('resources/love.png')
local vertices = {
{ 0, 0, 0, 0, 1, 0, 0 },
{ image:getWidth(), 0, 1, 0, 0, 1, 0 },
{ image:getWidth(), image:getHeight(), 1, 1, 0, 0, 1 },
{ 0, image:getHeight(), 0, 1, 1, 1, 0 },
}
local mesh = love.graphics.newMesh(vertices, 'fan')
local canvas = love.graphics.newCanvas(64, 64)
love.graphics.setCanvas(canvas)
love.graphics.clear(0, 0, 0, 1)
love.graphics.drawInstanced(mesh, 1000, 0, 0, 0, 1, 1)
love.graphics.setCanvas()
local imgdata = love.graphics.readbackTexture(canvas, {64, 0, 0, 0, 64, 64})
test:assertPixels(imgdata, {
red = {{0,0}},
green = {{63,0}},
blue = {{63,63}},
yellow = {{0,63}}
}, 'draw instances')
test:exportImg(imgdata)
end


Expand Down Expand Up @@ -1648,19 +1843,18 @@ love.test.graphics.setShader = function(test)
end


-- love.graphics.setStencilTest
love.test.graphics.setStencilTest = function(test)
-- love.graphics.setStencilMode
love.test.graphics.setStencilMode = function(test)
local canvas = love.graphics.newCanvas(16, 16)
love.graphics.setCanvas({canvas, stencil=true})
love.graphics.clear(0, 0, 0, 1)
love.graphics.stencil(function()
love.graphics.circle('fill', 8, 8, 6)
end, 'replace', 1)
love.graphics.setStencilTest('greater', 0)
love.graphics.setStencilMode('replace', 'always', 1)
love.graphics.circle('fill', 8, 8, 6)
love.graphics.setStencilMode('keep', 'greater', 0)
love.graphics.setColor(1, 0, 0, 1)
love.graphics.rectangle('fill', 0, 0, 16, 16)
love.graphics.setColor(1, 1, 1, 1)
love.graphics.setStencilTest()
love.graphics.setStencilMode()
love.graphics.setCanvas()
local imgdata = love.graphics.readbackTexture(canvas, {16, 0, 0, 0, 16, 16})
test:assertPixels(imgdata, {
Expand Down
Loading

0 comments on commit 8124804

Please sign in to comment.