diff --git a/testing/examples/lovetest_runAllTests.html b/testing/examples/lovetest_runAllTests.html index b972d61eb..906348df6 100644 --- a/testing/examples/lovetest_runAllTests.html +++ b/testing/examples/lovetest_runAllTests.html @@ -1 +1 @@ -

🔴 love.test



🟢 love.audio

\ No newline at end of file +

🔴 love.test



🟢 love.audio

\ No newline at end of file diff --git a/testing/examples/lovetest_runAllTests.md b/testing/examples/lovetest_runAllTests.md index fae747d8a..0c75c10f7 100644 --- a/testing/examples/lovetest_runAllTests.md +++ b/testing/examples/lovetest_runAllTests.md @@ -1,28 +1,28 @@ - + ### 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 diff --git a/testing/examples/lovetest_runAllTests.xml b/testing/examples/lovetest_runAllTests.xml index a2c161469..0ae096f1c 100644 --- a/testing/examples/lovetest_runAllTests.xml +++ b/testing/examples/lovetest_runAllTests.xml @@ -1,659 +1,650 @@ - - - + + + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - - + + - + - + - + - + - + - + - + - + - + - - + + - + - + - + - + - + - - + + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - - + + assert 8 [check glyph number] expected '97' got '0' - + - + - + - + - + - + - - + + - + - + - + - + - + - + - - + - + - - + - + - + - + - + - + - + - + - - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - - + + - + - + - + - + - - + + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - - + + - + - + - + - - + - - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - - - - - + - - + + - + - + - + - - + + - + - + - + - + - + - + - + - - + + - + - + - + - + - - + + - + - + - + - + - + - - + + - + - - + + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + \ No newline at end of file diff --git a/testing/output/expected/love.test.graphics.SpriteBatch-1.png b/testing/output/expected/love.test.graphics.SpriteBatch-1.png new file mode 100644 index 000000000..e3c032481 Binary files /dev/null and b/testing/output/expected/love.test.graphics.SpriteBatch-1.png differ diff --git a/testing/output/expected/love.test.graphics.SpriteBatch-2.png b/testing/output/expected/love.test.graphics.SpriteBatch-2.png new file mode 100644 index 000000000..3427e6141 Binary files /dev/null and b/testing/output/expected/love.test.graphics.SpriteBatch-2.png differ diff --git a/testing/output/expected/love.test.graphics.SpriteBatch-3.png b/testing/output/expected/love.test.graphics.SpriteBatch-3.png new file mode 100644 index 000000000..36ee516f3 Binary files /dev/null and b/testing/output/expected/love.test.graphics.SpriteBatch-3.png differ diff --git a/testing/output/expected/love.test.graphics.SpriteBatch-4.png b/testing/output/expected/love.test.graphics.SpriteBatch-4.png new file mode 100644 index 000000000..d33b0c1ce Binary files /dev/null and b/testing/output/expected/love.test.graphics.SpriteBatch-4.png differ diff --git a/testing/output/expected/love.test.graphics.SpriteBatch-5.png b/testing/output/expected/love.test.graphics.SpriteBatch-5.png new file mode 100644 index 000000000..9171baaec Binary files /dev/null and b/testing/output/expected/love.test.graphics.SpriteBatch-5.png differ diff --git a/testing/output/expected/love.test.graphics.Video-1.png b/testing/output/expected/love.test.graphics.Video-1.png new file mode 100644 index 000000000..ad8b44e9e Binary files /dev/null and b/testing/output/expected/love.test.graphics.Video-1.png differ diff --git a/testing/output/expected/love.test.graphics.drawInstanced-1.png b/testing/output/expected/love.test.graphics.drawInstanced-1.png new file mode 100644 index 000000000..8211034e0 Binary files /dev/null and b/testing/output/expected/love.test.graphics.drawInstanced-1.png differ diff --git a/testing/output/expected/love.test.graphics.setStencilTest-1.png b/testing/output/expected/love.test.graphics.setStencilMode-1.png similarity index 100% rename from testing/output/expected/love.test.graphics.setStencilTest-1.png rename to testing/output/expected/love.test.graphics.setStencilMode-1.png diff --git a/testing/readme.md b/testing/readme.md index c0eab1201..a6bace051 100644 --- a/testing/readme.md +++ b/testing/readme.md @@ -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 | @@ -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` @@ -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 --- @@ -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 \ No newline at end of file diff --git a/testing/tests/graphics.lua b/testing/tests/graphics.lua index 3c0544943..74efb796b 100644 --- a/testing/tests/graphics.lua +++ b/testing/tests/graphics.lua @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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, { diff --git a/testing/tests/physics.lua b/testing/tests/physics.lua index 929bbf0e6..a10f53bb7 100644 --- a/testing/tests/physics.lua +++ b/testing/tests/physics.lua @@ -20,12 +20,6 @@ love.test.physics.Contact = function(test) end --- Fixture (love.physics.newFixture) -love.test.physics.Fixture = function(test) - test:skipTest('test class needs writing') -end - - -- Joint (love.physics.newDistanceJoint) love.test.physics.Joint = function(test) test:skipTest('test class needs writing') @@ -33,6 +27,7 @@ end -- Shape (love.physics.newCircleShape) +-- @NOTE includes Fixture methods too enjoy love.test.physics.Shape = function(test) test:skipTest('test class needs writing') end @@ -40,7 +35,81 @@ end -- World (love.physics.newWorld) love.test.physics.World = function(test) - test:skipTest('test class needs writing') + -- create new world + local world = love.physics.newWorld(0, 0, false) + local body1 = love.physics.newBody(world, 0, 0, 'dynamic') + local rectangle1 = love.physics.newRectangleShape(body1, 0, 0, 10, 10) + test:assertObject(world) + -- check defaults + test:assertEquals(1, #world:getBodies(), 'check 1 body') + test:assertEquals(0, world:getBodies()[1]:getX(), 'check body prop x') + test:assertEquals(0, world:getBodies()[1]:getY(), 'check body prop y') + world:translateOrigin(-10, -10) + test:assertEquals(10, world:getBodies()[1]:getX(), 'check body prop change x') + test:assertEquals(10, world:getBodies()[1]:getY(), 'check body prop change y') + test:assertEquals(1, world:getBodyCount(), 'check 1 body count') + test:assertEquals(false, world:isDestroyed(), 'check not destroyed') + test:assertEquals(false, world:isLocked(), 'check not updating') + test:assertEquals(0, #world:getJoints(), 'check no joints') + test:assertEquals(0, world:getJointCount(), 'check no joints count') + test:assertEquals(0, world:getGravity(), 'check def gravity') + test:assertEquals(0, #world:getContacts(), 'check no contacts') + test:assertEquals(0, world:getContactCount(), 'check no contact count') + test:assertEquals(false, world:isSleepingAllowed(), 'check no sleep (till brooklyn)') + world:setSleepingAllowed(true) + test:assertEquals(true, world:isSleepingAllowed(), 'check can sleep') + -- check callbacks are called + local beginContact, endContact, preSolve, postSolve = world:getCallbacks() + test:assertEquals(nil, beginContact, 'check no begin contact callback') + test:assertEquals(nil, endContact, 'check no end contact callback') + test:assertEquals(nil, preSolve, 'check no pre solve callback') + test:assertEquals(nil, postSolve, 'check no post solve callback') + local beginContactCheck = false + local endContactCheck = false + local preSolveCheck = false + local postSolveCheck = false + local collisions = 0 + world:setCallbacks( + function() beginContactCheck = true; collisions = collisions + 1 end, + function() endContactCheck = true end, + function() preSolveCheck = true end, + function() postSolveCheck = true end + ) + local body2 = love.physics.newBody(world, 10, 10, 'dynamic') + local rectangle2 = love.physics.newRectangleShape(body2, 0, 0, 10, 10) + test:assertEquals(false, beginContactCheck, 'check world didnt update after adding body') + world:update(1) + test:assertEquals(true, beginContactCheck, 'check contact start') + test:assertEquals(true, preSolveCheck, 'check pre solve') + test:assertEquals(true, postSolveCheck, 'check post solve') + body2:setPosition(100, 100) + world:update(1) + test:assertEquals(true, endContactCheck, 'check contact end') + -- check point checking + local shapes = 0 + world:queryShapesInArea(0, 0, 10, 10, function(x) + shapes = shapes + 1 + end) + test:assertEquals(1, shapes, 'check shapes in area') + world:rayCast(0, 0, 200, 200, function(x) + shapes = shapes + 1 + return 1 + end) + test:assertEquals(3, shapes, 'check shapes in raycast') + -- change collision logic + test:assertEquals(nil, world:getContactFilter(), 'check def filter') + world:update(1) + world:setContactFilter(function(s1, s2) + return false -- nothing collides + end) + body2:setPosition(10, 10) + world:update(1) + test:assertEquals(1, collisions, 'check collision logic change') + -- final bits + world:setGravity(1, 1) + test:assertEquals(1, world:getGravity(), 'check grav change') + world:destroy() + test:assertEquals(true, world:isDestroyed(), 'check world destroyed') end @@ -54,14 +123,12 @@ end -- love.physics.getDistance love.test.physics.getDistance = function(test) -- setup two fixtues to check - local shape1 = love.physics.newEdgeShape(0, 0, 5, 5) - local shape2 = love.physics.newEdgeShape(10, 10, 15, 15) local world = love.physics.newWorld(0, 0, false) local body = love.physics.newBody(world, 10, 10, 'static') - local fixture1 = love.physics.newFixture(body, shape1, 1) - local fixture2 = love.physics.newFixture(body, shape2, 1) + local shape1 = love.physics.newEdgeShape(body, 0, 0, 5, 5) + local shape2 = love.physics.newEdgeShape(body, 10, 10, 15, 15) -- check distance between them - test:assertEquals(647106, math.floor(love.physics.getDistance(fixture1, fixture2)*100000), 'check distance matches') + test:assertEquals(647106, math.floor(love.physics.getDistance(shape1, shape2)*100000), 'check distance matches') end @@ -85,14 +152,18 @@ end -- love.physics.newChainShape -- @NOTE this is just basic nil checking, objs have their own test method love.test.physics.newChainShape = function(test) - test:assertObject(love.physics.newChainShape(true, 0, 0, 1, 0, 1, 1, 0, 1)) + local world = love.physics.newWorld(1, 1, true) + local body = love.physics.newBody(world, 10, 10, 'static') + test:assertObject(love.physics.newChainShape(body, true, 0, 0, 1, 0, 1, 1, 0, 1)) end -- love.physics.newCircleShape -- @NOTE this is just basic nil checking, objs have their own test method love.test.physics.newCircleShape = function(test) - test:assertObject(love.physics.newCircleShape(10)) + local world = love.physics.newWorld(1, 1, true) + local body = love.physics.newBody(world, 10, 10, 'static') + test:assertObject(love.physics.newCircleShape(body, 10)) end @@ -110,18 +181,9 @@ end -- love.physics.newEdgeShape -- @NOTE this is just basic nil checking, objs have their own test method love.test.physics.newEdgeShape = function(test) - local obj = love.physics.newEdgeShape(0, 0, 10, 10) - test:assertObject(obj) -end - - --- love.physics.newFixture --- @NOTE this is just basic nil checking, objs have their own test method -love.test.physics.newFixture = function(test) local world = love.physics.newWorld(1, 1, true) local body = love.physics.newBody(world, 10, 10, 'static') - local shape = love.physics.newCircleShape(10) - local obj = love.physics.newFixture(body, shape, 1) + local obj = love.physics.newEdgeShape(body, 0, 0, 10, 10) test:assertObject(obj) end @@ -176,7 +238,9 @@ end -- love.physics.newPolygonShape -- @NOTE this is just basic nil checking, objs have their own test method love.test.physics.newPolygonShape = function(test) - local obj = love.physics.newPolygonShape({0, 0, 2, 3, 2, 1, 3, 1, 5, 1}) + local world = love.physics.newWorld(1, 1, true) + local body = love.physics.newBody(world, 10, 10, 'static') + local obj = love.physics.newPolygonShape(body, {0, 0, 2, 3, 2, 1, 3, 1, 5, 1}) test:assertObject(obj) end @@ -206,8 +270,10 @@ end -- love.physics.newRectangleShape -- @NOTE this is just basic nil checking, objs have their own test method love.test.physics.newRectangleShape = function(test) - local shape1 = love.physics.newRectangleShape(10, 20) - local shape2 = love.physics.newRectangleShape(10, 10, 40, 30, 10) + local world = love.physics.newWorld(1, 1, true) + local body = love.physics.newBody(world, 10, 10, 'static') + local shape1 = love.physics.newRectangleShape(body, 10, 20) + local shape2 = love.physics.newRectangleShape(body, 10, 10, 40, 30, 10) test:assertObject(shape1) test:assertObject(shape2) end