diff --git a/testing/classes/TestMethod.lua b/testing/classes/TestMethod.lua index b0c763082..8fa55080f 100644 --- a/testing/classes/TestMethod.lua +++ b/testing/classes/TestMethod.lua @@ -189,14 +189,23 @@ TestMethod = { -- @param {table} obj - table to check is a valid love object -- @return {nil} assertObject = function(self, obj) - self:assertNotEquals(nil, obj, 'check not nill') + self:assertNotNil(obj) self:assertEquals('userdata', type(obj), 'check is userdata') - if obj ~= nil then + if obj ~= nil then self:assertNotEquals(nil, obj:type(), 'check has :type()') end end, + -- @method - TestMethod:assertNotNil() + -- @desc - quick assert for value not nil + -- @param {any} value - value to check not nil + -- @return {nil} + assertNotNil = function (self, value) + self:assertNotEquals(nil, value, 'check not nil') + end, + + -- @method - TestMethod:skipTest() -- @desc - used to mark this test as skipped for a specific reason @@ -289,10 +298,7 @@ TestMethod = { self.finish = love.timer.getTime() - self.start love.test.time = love.test.time + self.finish self.testmodule.time = self.testmodule.time + self.finish - local endtime = tostring(math.floor((love.timer.getTime() - self.start)*1000)) - if string.len(endtime) == 1 then endtime = ' ' .. endtime end - if string.len(endtime) == 2 then endtime = ' ' .. endtime end - if string.len(endtime) == 3 then endtime = ' ' .. endtime end + local endtime = UtilTimeFormat(love.timer.getTime() - self.start) -- get failure/skip message for output (if any) local failure = '' @@ -309,7 +315,7 @@ TestMethod = { -- append XML for the test class result self.testmodule.xml = self.testmodule.xml .. '\t\t\n' .. + '" time="' .. endtime .. '">\n' .. failure .. '\t\t\n' -- unused currently, adds a preview image for certain graphics methods to the output @@ -329,7 +335,7 @@ TestMethod = { '' .. '' .. status .. '' .. '' .. self.method .. '' .. - '' .. tostring(self.finish*1000) .. 'ms' .. + '' .. endtime .. 's' .. '' .. output .. preview .. '' .. '' @@ -350,10 +356,10 @@ TestMethod = { self.testmodule:log( self.testmodule.colors[self.result.result], ' ' .. tested .. matching, - ' ==> ' .. self.result.result .. ' - ' .. endtime .. 'ms ' .. + ' ==> ' .. self.result.result .. ' - ' .. endtime .. 's ' .. self.result.total .. msg ) end -} \ No newline at end of file +} diff --git a/testing/classes/TestModule.lua b/testing/classes/TestModule.lua index 379aac360..9ee6cd62e 100644 --- a/testing/classes/TestModule.lua +++ b/testing/classes/TestModule.lua @@ -83,12 +83,13 @@ TestModule = { -- the XML + HTML for the test to the testsuite output -- @return {nil} printResult = function(self) + local finaltime = UtilTimeFormat(self.time) -- add xml to main output love.test.xml = love.test.xml .. '\t\n' .. self.xml .. '\t\n' + '" time="' .. finaltime .. '">\n' .. self.xml .. '\t\n' -- add html to main output local status = '🔴' if self.failed == 0 then status = '🟢' end @@ -96,8 +97,8 @@ TestModule = { '
  • 🟢 ' .. tostring(self.passed) .. ' Tests
  • ' .. '
  • 🔴 ' .. tostring(self.failed) .. ' Failures
  • ' .. '
  • 🟡 ' .. tostring(self.skipped) .. ' Skipped
  • ' .. - '
  • ' .. tostring(self.time*1000) .. 'ms
  • ' .. '

    ' + '
  • ' .. finaltime .. 's


  • ' -- @TODO use mountFullPath to write output to src? love.filesystem.createDirectory('output') love.filesystem.write('output/' .. self.output .. '.xml', xml .. self.xml .. '') love.filesystem.write('output/' .. self.output .. '.html', html .. self.html .. '') - self.module:log('grey', '\nFINISHED - ' .. finaltime .. 'ms\n') + 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') @@ -156,4 +156,4 @@ TestSuite = { end -} \ No newline at end of file +} diff --git a/testing/conf.lua b/testing/conf.lua index 9f1ba5789..f04c2d90a 100644 --- a/testing/conf.lua +++ b/testing/conf.lua @@ -21,4 +21,4 @@ function love.conf(t) t.modules.timer = true t.modules.video = true t.modules.window = true -end \ No newline at end of file +end diff --git a/testing/examples/lovetest_runAllTests.html b/testing/examples/lovetest_runAllTests.html new file mode 100644 index 000000000..ac9b12d58 --- /dev/null +++ b/testing/examples/lovetest_runAllTests.html @@ -0,0 +1 @@ +

    🔴 love.test



    🟢 love.audio

    \ No newline at end of file diff --git a/testing/examples/lovetest_runAllTests.xml b/testing/examples/lovetest_runAllTests.xml new file mode 100644 index 000000000..9c69661ed --- /dev/null +++ b/testing/examples/lovetest_runAllTests.xml @@ -0,0 +1,578 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/testing/main.lua b/testing/main.lua index 205f0b786..c90040818 100644 --- a/testing/main.lua +++ b/testing/main.lua @@ -169,4 +169,10 @@ function UtilStringSplit(str, splitter) table.insert(splits, word) end return splits -end \ No newline at end of file +end + + +-- string time formatter +function UtilTimeFormat(seconds) + return string.format("%.3f", tostring(seconds)) +end diff --git a/testing/output/lovetest_runAllTests.html b/testing/output/lovetest_runAllTests.html deleted file mode 100644 index 164ade985..000000000 --- a/testing/output/lovetest_runAllTests.html +++ /dev/null @@ -1 +0,0 @@ -

    🔴 love.test



    🟢 love.audio

    \ No newline at end of file diff --git a/testing/output/lovetest_runAllTests.xml b/testing/output/lovetest_runAllTests.xml deleted file mode 100644 index a30afbbc2..000000000 --- a/testing/output/lovetest_runAllTests.xml +++ /dev/null @@ -1,385 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/testing/readme.md b/testing/readme.md index 5740a6b4e..4269e4447 100644 --- a/testing/readme.md +++ b/testing/readme.md @@ -84,19 +84,22 @@ This is the status of all module tests currently. -- [x] audio 26 PASSED | 0 FAILED | 0 SKIPPED -- [x] data 7 PASSED | 0 FAILED | 3 SKIPPED [SEE BELOW] -- [x] event 4 PASSED | 0 FAILED | 2 SKIPPED [SEE BELOW] --- [x] filesystem 26 PASSED | 1 FAILED | 2 SKIPPED [SEE BELOW] +-- [x] filesystem 27 PASSED | 0 FAILED | 2 SKIPPED -- [x] font 4 PASSED | 0 FAILED | 1 SKIPPED [SEE BELOW] --- [ ] graphics STILL TO BE DONE +-- [ ] graphics 65 PASSED | 0 FAILED | 31 SKIPPED [SEE BELOW] -- [x] image 3 PASSED | 0 FAILED | 0 SKIPPED --- [x] math 16 PASSED | 0 FAILED | 0 SKIPPED [SEE BELOW] --- [x] physics 21 PASSED | 1 FAILED | 0 SKIPPED [SEE BELOW] +-- [x] math 17 PASSED | 0 FAILED | 0 SKIPPED +-- [x] physics 22 PASSED | 0 FAILED | 0 SKIPPED -- [x] sound 2 PASSED | 0 FAILED | 0 SKIPPED --- [x] system 7 PASSED | 0 FAILED | 1 SKIPPED --- [ ] thread 3 PASSED | 0 FAILED | 0 SKIPPED --- [x] timer 6 PASSED | 0 FAILED | 0 SKIPPED [SEE BELOW] +-- [x] system 6 PASSED | 0 FAILED | 2 SKIPPED +-- [x] thread 3 PASSED | 0 FAILED | 0 SKIPPED +-- [x] timer 6 PASSED | 0 FAILED | 0 SKIPPED -- [x] video 1 PASSED | 0 FAILED | 0 SKIPPED --- [x] window 32 PASSED | 2 FAILED | 1 SKIPPED [SEE BELOW] +-- [x] window 32 PASSED | 2 FAILED | 2 SKIPPED [SEE BELOW] + -- [ ] objects STILL TO BE DONE +-------------------------------------------------------------------------------- +-- [x] totals 226 PASSED | 4 FAILED | 43 SKIPPED ``` The following modules are not covered as we can't really emulate input nicely: @@ -108,24 +111,17 @@ The following modules are not covered as we can't really emulate input nicely: Modules with some small bits needed or needing sense checking: - **love.data** - packing methods need writing cos i dont really get what they are - **love.event** - love.event.wait or love.event.pump need writing if possible I dunno how to check -- **love.filesystem** - getSource() / setSource() dont think we can test - **love.font** - newBMFontRasterizer() wiki entry is wrong so not sure whats expected -- **love.timer** - couple methods I don't know if you could reliably test specific values +- **love.graphics** - still need to do tests for the drawing and state methods - **love.image** - ideally isCompressed should have an example of all compressed files love can take - **love.math** - linearToGamma + gammaToLinear using direct formulas don't get same value back -- **love.window** - couple stuff just nil checked as I think it's hardware dependent, needs checking - -Modules still to be completed or barely started -- **love.graphics** - done 1 as an example of how we can test the drawing but not really started -- **love.objects** - done 1 as an example of how we can test objs with mini scenarios +- **love.objects** - not started properly yet --- ## Failures - **love.window.isMaximized()** - returns false after calling love.window.maximize? - **love.window.maximize()** - same as above -- **love.physics.newGearJoint()** - something changed in 12 -- **love.objects.File()** - dont think I understand the buffering system --- @@ -136,4 +132,4 @@ Modules still to be completed or barely started - [ ] Ability to test loading different combinations of modules - [ ] Performance tests -There is some unused code in the Test.lua class to add preview vs actual images to the HTML output \ No newline at end of file +There is some unused code in the Test.lua class to add preview vs actual images to the HTML output diff --git a/testing/resources/cubemap.png b/testing/resources/cubemap.png new file mode 100644 index 000000000..2b8b2ed0c Binary files /dev/null and b/testing/resources/cubemap.png differ diff --git a/testing/resources/love2.png b/testing/resources/love2.png new file mode 100644 index 000000000..e2612a857 Binary files /dev/null and b/testing/resources/love2.png differ diff --git a/testing/resources/love3.png b/testing/resources/love3.png new file mode 100644 index 000000000..e2612a857 Binary files /dev/null and b/testing/resources/love3.png differ diff --git a/testing/tests/audio.lua b/testing/tests/audio.lua index 0e33a7640..a174b48c8 100644 --- a/testing/tests/audio.lua +++ b/testing/tests/audio.lua @@ -3,9 +3,9 @@ -- love.audio.getActiveEffects love.test.audio.getActiveEffects = function(test) - -- tests - test:assertNotEquals(nil, love.audio.getActiveEffects(), 'check not nil') - test:assertEquals(0, #love.audio.getActiveEffects(), 'check no effects running') + -- check we get a value + test:assertNotNil(love.audio.getActiveEffects()) + -- check setting an effect active love.audio.setEffect('testeffect', { type = 'chorus', volume = 10 @@ -17,23 +17,25 @@ end -- love.audio.getActiveSourceCount love.test.audio.getActiveSourceCount = function(test) - -- tests - test:assertNotEquals(nil, love.audio.getActiveSourceCount(), 'check not nil') - test:assertEquals(0, love.audio.getActiveSourceCount(), 'check 0 by default') + -- check we get a value + test:assertNotNil(love.audio.getActiveSourceCount()) + -- check source isn't active by default local testsource = love.audio.newSource('resources/click.ogg', 'static') test:assertEquals(0, love.audio.getActiveSourceCount(), 'check not active') + -- check playing a source marks it as active love.audio.play(testsource) test:assertEquals(1, love.audio.getActiveSourceCount(), 'check now active') love.audio.pause() - testsource:release() end -- love.audio.getDistanceModel love.test.audio.getDistanceModel = function(test) - -- tests - test:assertNotEquals(nil, love.audio.getDistanceModel(), 'check not nil') + -- check we get a value + test:assertNotNil(love.audio.getDistanceModel()) + -- check default value from documentation test:assertEquals('inverseclamped', love.audio.getDistanceModel(), 'check default value') + -- check get correct value after setting love.audio.setDistanceModel('inverse') test:assertEquals('inverse', love.audio.getDistanceModel(), 'check setting model') end @@ -41,7 +43,9 @@ end -- love.audio.getDopplerScale love.test.audio.getDopplerScale = function(test) + -- check default value test:assertEquals(1, love.audio.getDopplerScale(), 'check default 1') + -- check correct value after setting to 0 love.audio.setDopplerScale(0) test:assertEquals(0, love.audio.getDopplerScale(), 'check setting to 0') love.audio.setDopplerScale(1) @@ -50,14 +54,15 @@ end -- love.audio.getEffect love.test.audio.getEffect = function(test) - -- setup + -- check getting a non-existent effect + test:assertEquals(nil, love.audio.getEffect('madeupname'), 'check wrong name') + -- check getting a valid effect love.audio.setEffect('testeffect', { type = 'chorus', volume = 10 }) - -- tests - test:assertEquals(nil, love.audio.getEffect('madeupname'), 'check wrong name') - test:assertNotEquals(nil, love.audio.getEffect('testeffect'), 'check not nil') + test:assertNotNil(love.audio.getEffect('testeffect')) + -- check effect values match creation values test:assertEquals('chorus', love.audio.getEffect('testeffect').type, 'check effect type') test:assertEquals(10, love.audio.getEffect('testeffect').volume, 'check effect volume') end @@ -66,23 +71,22 @@ end -- love.audio.getMaxSceneEffects -- @NOTE feel like this is platform specific number so best we can do is a nil? love.test.audio.getMaxSceneEffects = function(test) - test:assertNotEquals(nil, love.audio.getMaxSceneEffects(), 'check not nil') + test:assertNotNil(love.audio.getMaxSceneEffects()) end -- love.audio.getMaxSourceEffects -- @NOTE feel like this is platform specific number so best we can do is a nil? love.test.audio.getMaxSourceEffects = function(test) - test:assertNotEquals(nil, love.audio.getMaxSourceEffects(), 'check not nil') + test:assertNotNil(love.audio.getMaxSourceEffects()) end -- love.audio.getOrientation -- @NOTE is there an expected default listener pos? love.test.audio.getOrientation = function(test) - -- setup + -- checking getting values matches what was set love.audio.setOrientation(1, 2, 3, 4, 5, 6) - -- tests local fx, fy, fz, ux, uy, uz = love.audio.getOrientation() test:assertEquals(1, fx, 'check fx orientation') test:assertEquals(2, fy, 'check fy orientation') @@ -96,9 +100,8 @@ end -- love.audio.getPosition -- @NOTE is there an expected default listener pos? love.test.audio.getPosition = function(test) - -- setup + -- check getting values matches what was set love.audio.setPosition(1, 2, 3) - -- tests local x, y, z = love.audio.getPosition() test:assertEquals(1, x, 'check x position') test:assertEquals(2, y, 'check y position') @@ -107,16 +110,16 @@ end -- love.audio.getRecordingDevices +-- @NOTE hardware dependent so best can do is not nil check love.test.audio.getRecordingDevices = function(test) - test:assertNotEquals(nil, love.audio.getRecordingDevices(), 'check not nil') + test:assertNotNil(love.audio.getRecordingDevices()) end -- love.audio.getVelocity love.test.audio.getVelocity = function(test) - -- setup + -- check getting values matches what was set love.audio.setVelocity(1, 2, 3) - -- tests local x, y, z = love.audio.getVelocity() test:assertEquals(1, x, 'check x velocity') test:assertEquals(2, y, 'check y velocity') @@ -126,87 +129,74 @@ end -- love.audio.getVolume love.test.audio.getVolume = function(test) - -- setup + -- check getting values matches what was set love.audio.setVolume(0.5) - -- tests - test:assertNotEquals(nil, love.audio.getVolume(), 'check not nil') test:assertEquals(0.5, love.audio.getVolume(), 'check matches set') end -- love.audio.isEffectsSupported love.test.audio.isEffectsSupported = function(test) - test:assertNotEquals(nil, love.audio.isEffectsSupported(), 'check not nil') + test:assertNotNil(love.audio.isEffectsSupported()) end -- love.audio.newQueueableSource -- @NOTE this is just basic nil checking, full obj test are in objects.lua love.test.audio.newQueueableSource = function(test) - local source = love.audio.newQueueableSource(32, 8, 1, 8) - test:assertObject(source) - source:release() + test:assertObject(love.audio.newQueueableSource(32, 8, 1, 8)) end -- love.audio.newSource -- @NOTE this is just basic nil checking, full obj test are in objects.lua love.test.audio.newSource = function(test) - -- setup - local source1 = love.audio.newSource('resources/click.ogg', 'static') - local source2 = love.audio.newSource('resources/click.ogg', 'stream') - -- tests - test:assertObject(source1) - test:assertObject(source2) - -- cleanup - source1:release() - source2:release() + test:assertObject(love.audio.newSource('resources/click.ogg', 'static')) + test:assertObject(love.audio.newSource('resources/click.ogg', 'stream')) end -- love.audio.pause love.test.audio.pause = function(test) - -- tests + -- check nothing paused (as should be nothing playing) local nopauses = love.audio.pause() - test:assertNotEquals(nil, nopauses, 'check not nil') test:assertEquals(0, #nopauses, 'check nothing paused') + -- check 1 source paused after playing/pausing 1 local source = love.audio.newSource('resources/click.ogg', 'static') love.audio.play(source) local onepause = love.audio.pause() test:assertEquals(1, #onepause, 'check 1 paused') - source:release() end -- love.audio.play love.test.audio.play = function(test) - -- setup + -- check playing source is detected local source = love.audio.newSource('resources/click.ogg', 'static') - -- tests love.audio.play(source) test:assertEquals(true, source:isPlaying(), 'check something playing') love.audio.pause() - source:release() end -- love.audio.setDistanceModel love.test.audio.setDistanceModel = function(test) - -- tests + -- check setting each of the distance models is accepted and val returned local distancemodel = { 'none', 'inverse', 'inverseclamped', 'linear', 'linearclamped', 'exponent', 'exponentclamped' } for d=1,#distancemodel do love.audio.setDistanceModel(distancemodel[d]) - test:assertEquals(distancemodel[d], love.audio.getDistanceModel(), 'check model set to ' .. distancemodel[d]) + test:assertEquals(distancemodel[d], love.audio.getDistanceModel(), + 'check model set to ' .. distancemodel[d]) end end -- love.audio.setDopplerScale love.test.audio.setDopplerScale = function(test) - -- tests + -- check setting value is returned properly love.audio.setDopplerScale(0) test:assertEquals(0, love.audio.getDopplerScale(), 'check set to 0') love.audio.setDopplerScale(1) @@ -216,12 +206,13 @@ end -- love.audio.setEffect love.test.audio.setEffect = function(test) - -- tests + -- check effect is set correctly local effect = love.audio.setEffect('testeffect', { type = 'chorus', volume = 10 }) test:assertEquals(true, effect, 'check effect created') + -- check values set match local settings = love.audio.getEffect('testeffect') test:assertEquals('chorus', settings.type, 'check effect type') test:assertEquals(10, settings.volume, 'check effect volume') @@ -230,15 +221,14 @@ end -- love.audio.setMixWithSystem love.test.audio.setMixWithSystem = function(test) - test:assertNotEquals(nil, love.audio.setMixWithSystem(true), 'check not nil') + test:assertNotNil(love.audio.setMixWithSystem(true)) end -- love.audio.setOrientation love.test.audio.setOrientation = function(test) - -- setup + -- check setting orientation vals are returned love.audio.setOrientation(1, 2, 3, 4, 5, 6) - -- tests local fx, fy, fz, ux, uy, uz = love.audio.getOrientation() test:assertEquals(1, fx, 'check fx orientation') test:assertEquals(2, fy, 'check fy orientation') @@ -251,9 +241,8 @@ end -- love.audio.setPosition love.test.audio.setPosition = function(test) - -- setup + -- check setting position vals are returned love.audio.setPosition(1, 2, 3) - -- tests local x, y, z = love.audio.getPosition() test:assertEquals(1, x, 'check x position') test:assertEquals(2, y, 'check y position') @@ -263,9 +252,8 @@ end -- love.audio.setVelocity love.test.audio.setVelocity = function(test) - -- setup + -- check setting velocity vals are returned love.audio.setVelocity(1, 2, 3) - -- tests local x, y, z = love.audio.getVelocity() test:assertEquals(1, x, 'check x velocity') test:assertEquals(2, y, 'check y velocity') @@ -275,22 +263,19 @@ end -- love.audio.setVolume love.test.audio.setVolume = function(test) - -- setup + -- check setting volume works love.audio.setVolume(0.5) - -- tests - test:assertNotEquals(nil, love.audio.getVolume(), 'check not nil') test:assertEquals(0.5, love.audio.getVolume(), 'check set to 0.5') end -- love.audio.stop love.test.audio.stop = function(test) - -- setup + -- check source is playing first local source = love.audio.newSource('resources/click.ogg', 'static') love.audio.play(source) - -- tests test:assertEquals(true, source:isPlaying(), 'check is playing') + -- check source is then stopped love.audio.stop() test:assertEquals(false, source:isPlaying(), 'check stopped playing') - source:release() -end \ No newline at end of file +end diff --git a/testing/tests/data.lua b/testing/tests/data.lua index d59d192ba..76abdf5c7 100644 --- a/testing/tests/data.lua +++ b/testing/tests/data.lua @@ -3,9 +3,8 @@ -- love.data.compress love.test.data.compress = function(test) - -- here just testing each combo 'works', in decompress's test method + -- here just testing each combo 'works' - in decompress's test method -- we actually check the compress + decompress give the right value back - -- setup local compressions = { { love.data.compress('string', 'lz4', 'helloworld', -1), 'string'}, { love.data.compress('string', 'lz4', 'helloworld', 0), 'string'}, @@ -26,9 +25,8 @@ love.test.data.compress = function(test) { love.data.compress('data', 'gzip', 'helloworld', 0), 'userdata'}, { love.data.compress('data', 'gzip', 'helloworld', 9), 'userdata'} } - -- tests for c=1,#compressions do - test:assertNotEquals(nil, compressions[c][1], 'check not nil') + test:assertNotNil(compressions[c][1]) -- sense check return type and make sure bytedata returns are an object test:assertEquals(compressions[c][2], type(compressions[c][1]), 'check is userdata') if compressions[c][2] == 'userdata' then @@ -40,12 +38,12 @@ end -- love.data.decode love.test.data.decode = function(test) - -- setup + -- setup encoded strings local str1 = love.data.encode('string', 'base64', 'helloworld', 0) local str2 = love.data.encode('string', 'hex', 'helloworld') local str3 = love.data.encode('data', 'base64', 'helloworld', 0) local str4 = love.data.encode('data', 'hex', 'helloworld') - -- tests + -- check value matches expected when decoded back test:assertEquals('helloworld', love.data.decode('string', 'base64', str1), 'check string base64 decode') test:assertEquals('helloworld', love.data.decode('string', 'hex', str2), 'check string hex decode') test:assertEquals(love.data.newByteData('helloworld'):getString(), love.data.decode('data', 'base64', str3):getString(), 'check data base64 decode') @@ -55,7 +53,7 @@ end -- love.data.decompress love.test.data.decompress = function(test) - -- setup + -- setup compressed data for each combination local str1 = love.data.compress('string', 'lz4', 'helloworld', -1) local str2 = love.data.compress('string', 'lz4', 'helloworld', 0) local str3 = love.data.compress('string', 'lz4', 'helloworld', 9) @@ -74,7 +72,7 @@ love.test.data.decompress = function(test) local str16 = love.data.compress('data', 'gzip', 'helloworld', -1) local str17 = love.data.compress('data', 'gzip', 'helloworld', 0) local str18 = love.data.compress('data', 'gzip', 'helloworld', 9) - -- tests + -- check decompressed value matches whats expected test:assertEquals('helloworld', love.data.decompress('string', 'lz4', str1), 'check string lz4 decompress') test:assertEquals('helloworld', love.data.decompress('string', 'lz4', str2), 'check string lz4 decompress') test:assertEquals('helloworld', love.data.decompress('string', 'lz4', str3), 'check string lz4 decompress') @@ -98,9 +96,8 @@ end -- love.data.encode love.test.data.encode = function(test) - -- here just testing each combo 'works', in decode's test method + -- here just testing each combo 'works' - in decode's test method -- we actually check the encode + decode give the right value back - -- setup local encodes = { { love.data.encode('string', 'base64', 'helloworld', 0), 'string'}, { love.data.encode('string', 'base64', 'helloworld', 2), 'string'}, @@ -109,9 +106,8 @@ love.test.data.encode = function(test) { love.data.encode('data', 'base64', 'helloworld', 2), 'userdata'}, { love.data.encode('data', 'hex', 'helloworld'), 'userdata'} } - -- tests for e=1,#encodes do - test:assertNotEquals(nil, encodes[e][1], 'check not nil') + test:assertNotNil(encodes[e][1]) -- sense check return type and make sure bytedata returns are an object test:assertEquals(encodes[e][2], type(encodes[e][1]), 'check is usedata') if encodes[e][2] == 'userdata' then @@ -123,22 +119,22 @@ end -- love.data.getPackedSize --- @NOTE I dont really get the packing types of lua so best someone else writes this one +-- @NOTE I don't really get what lua packing types are so skipping for now - ell love.test.data.getPackedSize = function(test) - test:skipTest('dont understand lua packing types') + test:skipTest('test method needs writing') end -- love.data.hash love.test.data.hash = function(test) - -- setup + -- setup all the different hashing types local str1 = love.data.hash('md5', 'helloworld') local str2 = love.data.hash('sha1', 'helloworld') local str3 = love.data.hash('sha224', 'helloworld') local str4 = love.data.hash('sha256', 'helloworld') local str5 = love.data.hash('sha384', 'helloworld') local str6 = love.data.hash('sha512', 'helloworld') - -- tests + -- check encoded hash value matches what's expected for that algo test:assertEquals('fc5e038d38a57032085441e7fe7010b0', love.data.encode("string", "hex", str1), 'check md5 encode') test:assertEquals('6adfb183a4a2c94a2f92dab5ade762a47889a5a1', love.data.encode("string", "hex", str2), 'check sha1 encode') test:assertEquals('b033d770602994efa135c5248af300d81567ad5b59cec4bccbf15bcc', love.data.encode("string", "hex", str3), 'check sha224 encode') @@ -151,32 +147,26 @@ end -- love.data.newByteData -- @NOTE this is just basic nil checking, full obj test are in objects.lua love.test.data.newByteData = function(test) - -- setup - local bytedata = love.data.newByteData('helloworld') - -- tests - test:assertObject(bytedata) + test:assertObject(love.data.newByteData('helloworld')) end -- love.data.newDataView -- @NOTE this is just basic nil checking, full obj test are in objects.lua love.test.data.newDataView = function(test) - -- setup - local dataview = love.data.newDataView(love.data.newByteData('helloworld'), 0, 10) - -- tests - test:assertObject(dataview) + test:assertObject(love.data.newDataView(love.data.newByteData('helloworld'), 0, 10)) end -- love.data.pack --- @NOTE i dont really get the packing types of lua so best someone else writes this one +-- @NOTE I don't really get what lua packing types are so skipping for now - ell love.test.data.pack = function(test) - test:skipTest('dont understand lua packing types') + test:skipTest('test method needs writing') end -- love.data.unpack --- @NOTE i dont really get the packing types of lua so best someone else writes this one +-- @NOTE I don't really get what lua packing types are so skipping for now - ell love.test.data.unpack = function(test) - test:skipTest('dont understand lua packing types') -end \ No newline at end of file + test:skipTest('test method needs writing') +end diff --git a/testing/tests/event.lua b/testing/tests/event.lua index 8c552c03e..56650250f 100644 --- a/testing/tests/event.lua +++ b/testing/tests/event.lua @@ -3,11 +3,11 @@ -- love.event.clear love.test.event.clear = function(test) - -- setup + -- push some events first love.event.push('test', 1, 2, 3) love.event.push('test', 1, 2, 3) love.event.push('test', 1, 2, 3) - -- tests + -- check after calling clear there are no events left love.event.clear() local count = 0 for n, a, b, c, d, e, f in love.event.poll() do @@ -19,11 +19,11 @@ end -- love.event.poll love.test.event.poll = function(test) - -- setup + -- push some events first love.event.push('test', 1, 2, 3) love.event.push('test', 1, 2, 3) love.event.push('test', 1, 2, 3) - -- tests + -- check poll recieves all events local count = 0 for n, a, b, c, d, e, f in love.event.poll() do count = count + 1 @@ -33,15 +33,15 @@ end -- love.event.pump --- @NOTE dont think can really test as internal? +-- @NOTE dont think can really test as internally used love.test.event.pump = function(test) - test:skipTest('not sure we can test when its internal?') + test:skipTest('not sure can be tested as used internally') end -- love.event.push love.test.event.push = function(test) - -- test + -- check pushing some different types love.event.push('add', 1, 2, 3) love.event.push('ignore', 1, 2, 3) love.event.push('add', 1, 2, 3) @@ -58,10 +58,10 @@ end -- love.event.quit love.test.event.quit = function(test) + -- setting this overrides the quit hook to prevent actually quitting love.test.module.fakequit = true - -- this should call love.quit, which will prevent the quit - -- if this fails then the test would just abort here love.event.quit(0) + -- if it failed we'd have quit here test:assertEquals(true, true, 'check quit hook called') end @@ -69,5 +69,5 @@ end -- love.event.wait -- @NOTE not sure best way to test this one love.test.event.wait = function(test) - test:skipTest('not sure on best way to test this') -end \ No newline at end of file + test:skipTest('test method needs writing') +end diff --git a/testing/tests/filesystem.lua b/testing/tests/filesystem.lua index 5779660b3..a360dc6d8 100644 --- a/testing/tests/filesystem.lua +++ b/testing/tests/filesystem.lua @@ -3,15 +3,16 @@ -- love.filesystem.append love.test.filesystem.append = function(test) - -- setup + -- create a new file to test with love.filesystem.write('filesystem.append.txt', 'foo') - -- test + -- try appending text and check new file contents/size matches local success, message = love.filesystem.append('filesystem.append.txt', 'bar') test:assertNotEquals(false, success, 'check success') test:assertEquals(nil, message, 'check no error msg') local contents, size = love.filesystem.read('filesystem.append.txt') test:assertEquals(contents, 'foobar', 'check file contents') test:assertEquals(size, 6, 'check file size') + -- check appending a specific no. of bytes love.filesystem.append('filesystem.append.txt', 'foobarfoobarfoo', 6) contents, size = love.filesystem.read('filesystem.append.txt') test:assertEquals(contents, 'foobarfoobar', 'check appended contents') @@ -22,14 +23,15 @@ end -- love.filesystem.areSymlinksEnabled --- @NOTE this one, need to see if default val is consistent on platforms? +-- @NOTE best can do here is just check not nil love.test.filesystem.areSymlinksEnabled = function(test) - test:assertNotEquals(nil, love.filesystem.areSymlinksEnabled()) + test:assertNotNil(love.filesystem.areSymlinksEnabled()) end -- love.filesystem.createDirectory love.test.filesystem.createDirectory = function(test) + -- try creating a dir + subdir and check both exist local success = love.filesystem.createDirectory('foo/bar') test:assertNotEquals(false, success, 'check success') test:assertNotEquals(nil, love.filesystem.getInfo('foo', 'directory'), 'check directory created') @@ -43,23 +45,24 @@ end -- love.filesystem.getAppdataDirectory -- @NOTE i think this is too platform dependent to be tested nicely love.test.filesystem.getAppdataDirectory = function(test) - test:assertNotEquals(nil, love.filesystem.getAppdataDirectory(), 'check not nill') + test:assertNotNil(love.filesystem.getAppdataDirectory()) end -- love.filesystem.getCRequirePath love.test.filesystem.getCRequirePath = function(test) + -- check default value from documentation test:assertEquals('??', love.filesystem.getCRequirePath(), 'check default value') end -- love.filesystem.getDirectoryItems love.test.filesystem.getDirectoryItems = function(test) - -- setup + -- create a dir + subdir with 2 files love.filesystem.createDirectory('foo/bar') love.filesystem.write('foo/file1.txt', 'file1') love.filesystem.write('foo/bar/file2.txt', 'file2') - -- tests + -- check both the file + subdir exist in the item list local files = love.filesystem.getDirectoryItems('foo') local hasfile = false local hasdir = false @@ -80,23 +83,23 @@ end -- love.filesystem.getIdentity love.test.filesystem.getIdentity = function(test) - -- setup + -- check setting identity matches local original = love.filesystem.getIdentity() love.filesystem.setIdentity('lover') - -- test test:assertEquals('lover', love.filesystem.getIdentity(), 'check identity matches') - -- cleanup + -- put back to original value love.filesystem.setIdentity(original) end -- love.filesystem.getRealDirectory love.test.filesystem.getRealDirectory = function(test) - -- setup + -- make a test dir + file first love.filesystem.createDirectory('foo') love.filesystem.write('foo/test.txt', 'test') - -- test - test:assertEquals(love.filesystem.getSaveDirectory(), love.filesystem.getRealDirectory('foo/test.txt'), 'check directory matches') + -- check save dir matches the real dir we just wrote to + test:assertEquals(love.filesystem.getSaveDirectory(), + love.filesystem.getRealDirectory('foo/test.txt'), 'check directory matches') -- cleanup love.filesystem.remove('foo/test.txt') love.filesystem.remove('foo') @@ -105,51 +108,52 @@ end -- love.filesystem.getRequirePath love.test.filesystem.getRequirePath = function(test) - test:assertEquals('?.lua;?/init.lua', love.filesystem.getRequirePath(), 'check default value') + test:assertEquals('?.lua;?/init.lua', + love.filesystem.getRequirePath(), 'check default value') end -- love.filesystem.getSource -- @NOTE i dont think we can test this cos love calls it first love.test.filesystem.getSource = function(test) - test:skipTest('not sure we can test when its internal?') + test:skipTest('not sure can be tested as used internally') end -- love.filesystem.getSourceBaseDirectory -- @NOTE i think this is too platform dependent to be tested nicely love.test.filesystem.getSourceBaseDirectory = function(test) - test:assertNotEquals(nil, love.filesystem.getSourceBaseDirectory(), 'check not nil') + test:assertNotNil(love.filesystem.getSourceBaseDirectory()) end -- love.filesystem.getUserDirectory -- @NOTE i think this is too platform dependent to be tested nicely love.test.filesystem.getUserDirectory = function(test) - test:assertNotEquals(nil, love.filesystem.getUserDirectory(), 'check not nil') + test:assertNotNil(love.filesystem.getUserDirectory()) end -- love.filesystem.getWorkingDirectory -- @NOTE i think this is too platform dependent to be tested nicely love.test.filesystem.getWorkingDirectory = function(test) - test:assertNotEquals(nil, love.filesystem.getWorkingDirectory(), 'check not nil') + test:assertNotNil(love.filesystem.getWorkingDirectory()) end -- love.filesystem.getSaveDirectory -- @NOTE i think this is too platform dependent to be tested nicely love.test.filesystem.getSaveDirectory = function(test) - test:assertNotEquals(nil, love.filesystem.getSaveDirectory(), 'check not nil') + test:assertNotNil(love.filesystem.getSaveDirectory()) end -- love.filesystem.getInfo love.test.filesystem.getInfo = function(test) - -- setup + -- create a dir and subdir with a file love.filesystem.createDirectory('foo/bar') love.filesystem.write('foo/bar/file2.txt', 'file2') - -- tests + -- check getinfo returns the correct values test:assertEquals(nil, love.filesystem.getInfo('foo/bar/file2.txt', 'directory'), 'check not directory') test:assertNotEquals(nil, love.filesystem.getInfo('foo/bar/file2.txt'), 'check info not nil') test:assertEquals(love.filesystem.getInfo('foo/bar/file2.txt').size, 5, 'check info size match') @@ -164,18 +168,18 @@ end -- love.filesystem.isFused love.test.filesystem.isFused = function(test) -- kinda assuming you'd run the testsuite in a non-fused game - test:assertEquals(love.filesystem.isFused(), false, 'check default value') + test:assertEquals(love.filesystem.isFused(), false, 'check not fused') end -- love.filesystem.lines love.test.filesystem.lines = function(test) - -- setup + -- check lines returns the 3 lines expected love.filesystem.write('file.txt', 'line1\nline2\nline3') - -- tests local linenum = 1 for line in love.filesystem.lines('file.txt') do test:assertEquals('line' .. tostring(linenum), line, 'check line matches') + -- also check it removes newlines like the docs says it does test:assertEquals(nil, string.find(line, '\n'), 'check newline removed') linenum = linenum + 1 end @@ -186,15 +190,17 @@ end -- love.filesystem.load love.test.filesystem.load = function(test) - -- setup + -- setup some fake lua files love.filesystem.write('test1.lua', 'function test()\nreturn 1\nend\nreturn test()') love.filesystem.write('test2.lua', 'function test()\nreturn 1') - -- tests + -- check file that doesn't exist local chunk, errormsg = love.filesystem.load('faker.lua') test:assertEquals(nil, chunk, 'check file doesnt exist') + -- check valid lua file chunk, errormsg = love.filesystem.load('test1.lua') test:assertEquals(nil, errormsg, 'check no error message') test:assertEquals(1, chunk(), 'check lua file runs') + -- check invalid lua file local ok, chunk, err = pcall(love.filesystem.load, 'test2.lua') test:assertEquals(false, ok, 'check invalid lua file') -- cleanup @@ -205,10 +211,10 @@ end -- love.filesystem.mount love.test.filesystem.mount = function(test) - -- setup + -- write an example zip to savedir to use local contents, size = love.filesystem.read('resources/test.zip') -- contains test.txt love.filesystem.write('test.zip', contents, size) - -- tests + -- check mounting file and check contents are mounted local success = love.filesystem.mount('test.zip', 'test') test:assertEquals(true, success, 'check success') test:assertNotEquals(nil, love.filesystem.getInfo('test'), 'check mount not nil') @@ -222,45 +228,31 @@ love.test.filesystem.mount = function(test) end --- love.filesystem.newFile +-- love.filesystem.openFile -- @NOTE this is just basic nil checking, full obj test are in objects.lua -love.test.filesystem.newFile = function(test) - -- setup - local file = love.filesystem.newFile('file1') - local file_r, err_r = love.filesystem.newFile('file2', 'r') - local file_w, err_w = love.filesystem.newFile('file2', 'w') - local file_a, err_a = love.filesystem.newFile('file2', 'a') - local file_c, err_c = love.filesystem.newFile('file2', 'c') - -- tests - test:assertNotEquals(nil, file, 'check file made') - test:assertNotEquals(nil, file_r, 'check file made') - test:assertNotEquals(nil, file_w, 'check file made') - test:assertNotEquals(nil, file_a, 'check file made') - test:assertNotEquals(nil, file_c, 'check file made') - -- cleanup - if file ~= nil then file:release() end - if file_r ~= nil then file_r:release() end - if file_w ~= nil then file_w:release() end - if file_a ~= nil then file_a:release() end - if file_c ~= nil then file_c:release() end +love.test.filesystem.openFile = function(test) + test:assertNotNil(love.filesystem.openFile('file2', 'r')) + test:assertNotNil(love.filesystem.openFile('file2', 'w')) + test:assertNotNil(love.filesystem.openFile('file2', 'a')) + test:assertNotNil(love.filesystem.openFile('file2', 'c')) end -- love.filesystem.newFileData -- @NOTE this is just basic nil checking, full obj test are in objects.lua love.test.filesystem.newFileData = function(test) - local data = love.filesystem.newFileData('helloworld', 'file1') - test:assertNotEquals(nil, data, 'check not nil') - data:release() + test:assertNotNil(love.filesystem.newFileData('helloworld', 'file1')) end -- love.filesystem.read love.test.filesystem.read = function(test) + -- check reading a full file local content, size = love.filesystem.read('resources/test.txt') test:assertNotEquals(nil, content, 'check not nil') test:assertEquals('helloworld', content, 'check content match') test:assertEquals(10, size, 'check size match') + -- check reading partial file content, size = love.filesystem.read('resources/test.txt', 5) test:assertNotEquals(nil, content, 'check not nil') test:assertEquals('hello', content, 'check content match') @@ -270,21 +262,22 @@ end -- love.filesystem.remove love.test.filesystem.remove = function(test) - -- setup + -- create a dir + subdir with a file love.filesystem.createDirectory('foo/bar') love.filesystem.write('foo/bar/file2.txt', 'helloworld') - -- tests + -- check removing files + dirs (should fail to remove dir if file inside) test:assertEquals(false, love.filesystem.remove('foo'), 'check fail when file inside') test:assertEquals(false, love.filesystem.remove('foo/bar'), 'check fail when file inside') test:assertEquals(true, love.filesystem.remove('foo/bar/file2.txt'), 'check file removed') test:assertEquals(true, love.filesystem.remove('foo/bar'), 'check subdirectory removed') test:assertEquals(true, love.filesystem.remove('foo'), 'check directory removed') - -- cleanup not needed here + -- cleanup not needed here hopefully... end -- love.filesystem.setCRequirePath love.test.filesystem.setCRequirePath = function(test) + -- check setting path val is returned love.filesystem.setCRequirePath('/??') test:assertEquals('/??', love.filesystem.getCRequirePath(), 'check crequirepath value') love.filesystem.setCRequirePath('??') @@ -293,22 +286,21 @@ end -- love.filesystem.setIdentity love.test.filesystem.setIdentity = function(test) - -- setup + -- check setting identity val is returned local original = love.filesystem.getIdentity() - -- test love.filesystem.setIdentity('lover') test:assertEquals('lover', love.filesystem.getIdentity(), 'check indentity value') - -- cleanup + -- return value to original love.filesystem.setIdentity(original) end -- love.filesystem.setRequirePath love.test.filesystem.setRequirePath = function(test) - -- test + -- check setting path val is returned love.filesystem.setRequirePath('?.lua;?/start.lua') test:assertEquals('?.lua;?/start.lua', love.filesystem.getRequirePath(), 'check require path') - -- cleanup + -- reset to default love.filesystem.setRequirePath('?.lua;?/init.lua') end @@ -316,17 +308,17 @@ end -- love.filesystem.setSource -- @NOTE dont think can test this cos used internally? love.test.filesystem.setSource = function(test) - test:skipTest('not sure we can test when its internal?') + test:skipTest('not sure can be tested as used internally') end -- love.filesystem.unmount love.test.filesystem.unmount = function(test) - --setup + -- create a zip file mounted to use local contents, size = love.filesystem.read('resources/test.zip') -- contains test.txt love.filesystem.write('test.zip', contents, size) love.filesystem.mount('test.zip', 'test') - -- tests + -- check mounted, unmount, then check its unmounted test:assertNotEquals(nil, love.filesystem.getInfo('test/test.txt'), 'check mount exists') love.filesystem.unmount('test.zip') test:assertEquals(nil, love.filesystem.getInfo('test/test.txt'), 'check unmounted') @@ -339,11 +331,10 @@ end -- love.filesystem.write love.test.filesystem.write = function(test) - -- setup + -- check writing a bunch of files matches whats read back love.filesystem.write('test1.txt', 'helloworld') love.filesystem.write('test2.txt', 'helloworld', 10) love.filesystem.write('test3.txt', 'helloworld', 5) - -- test test:assertEquals('helloworld', love.filesystem.read('test1.txt'), 'check read file') test:assertEquals('helloworld', love.filesystem.read('test2.txt'), 'check read all') test:assertEquals('hello', love.filesystem.read('test3.txt'), 'check read partial') @@ -351,4 +342,4 @@ love.test.filesystem.write = function(test) love.filesystem.remove('test1.txt') love.filesystem.remove('test2.txt') love.filesystem.remove('test3.txt') -end \ No newline at end of file +end diff --git a/testing/tests/font.lua b/testing/tests/font.lua index 6c5d440fb..84c3f4568 100644 --- a/testing/tests/font.lua +++ b/testing/tests/font.lua @@ -16,9 +16,6 @@ love.test.font.newGlyphData = function(test) local rasterizer = love.font.newImageRasterizer(img, 'ABC', 0, 1); local glyphdata = love.font.newGlyphData(rasterizer, 65) test:assertObject(glyphdata) - img:release() - rasterizer:release() - glyphdata:release() end @@ -28,27 +25,19 @@ love.test.font.newImageRasterizer = function(test) local img = love.image.newImageData('resources/love.png') local rasterizer = love.font.newImageRasterizer(img, 'ABC', 0, 1); test:assertObject(rasterizer) - img:release() - rasterizer:release() end -- love.font.newRasterizer -- @NOTE this is just basic nil checking, full obj test are in objects.lua love.test.font.newRasterizer = function(test) - local rasterizer = love.font.newRasterizer('resources/font.ttf'); - test:assertObject(rasterizer) - rasterizer:release() + test:assertObject(love.font.newRasterizer('resources/font.ttf')) end -- love.font.newTrueTypeRasterizer -- @NOTE this is just basic nil checking, full obj test are in objects.lua love.test.font.newTrueTypeRasterizer = function(test) - local defaltraster = love.font.newTrueTypeRasterizer(12, "normal", 1) - local customraster = love.font.newTrueTypeRasterizer('resources/font.ttf', 8, "normal", 1) - test:assertObject(defaltraster) - test:assertObject(customraster) - defaltraster:release() - customraster:release() -end \ No newline at end of file + test:assertObject(love.font.newTrueTypeRasterizer(12, "normal", 1)) + test:assertObject(love.font.newTrueTypeRasterizer('resources/font.ttf', 8, "normal", 1)) +end diff --git a/testing/tests/graphics.lua b/testing/tests/graphics.lua index 877e6b7d6..2b8726e5e 100644 --- a/testing/tests/graphics.lua +++ b/testing/tests/graphics.lua @@ -1,9 +1,102 @@ -- love.graphics --- DRAWING +-------------------------------------------------------------------------------- +-------------------------------------------------------------------------------- +------------------------------------DRAWING------------------------------------- +-------------------------------------------------------------------------------- +-------------------------------------------------------------------------------- +-- love.graphics.arc +love.test.graphics.arc = function(test) + test:skipTest('test method needs writing') +end + + +-- love.graphics.circle +love.test.graphics.circle = function(test) + test:skipTest('test method needs writing') +end + + +-- love.graphics.clear +love.test.graphics.clear = function(test) + test:skipTest('test method needs writing') +end + + +-- love.graphics.discard +love.test.graphics.discard = function(test) + test:skipTest('test method needs writing') +end + + +-- love.graphics.draw +love.test.graphics.draw = function(test) + test:skipTest('test method needs writing') +end + + +-- love.graphics.drawInstanced +love.test.graphics.drawInstanced = function(test) + test:skipTest('test method needs writing') +end + + +-- love.graphics.drawLayer +love.test.graphics.drawLayer = function(test) + test:skipTest('test method needs writing') +end + + +-- love.graphics.ellipse +love.test.graphics.ellipse = function(test) + test:skipTest('test method needs writing') +end + + +-- love.graphics.flushBatch +love.test.graphics.flushBatch = function(test) + test:skipTest('test method needs writing') +end + + +-- love.graphics.line +love.test.graphics.line = function(test) + test:skipTest('test method needs writing') +end + + +-- love.graphics.points +love.test.graphics.points = function(test) + test:skipTest('test method needs writing') +end + + +-- love.graphics.polygon +love.test.graphics.polygon = function(test) + test:skipTest('test method needs writing') +end + + +-- love.graphics.present +love.test.graphics.present = function(test) + test:skipTest('test method needs writing') +end + + +-- love.graphics.print +love.test.graphics.print = function(test) + test:skipTest('test method needs writing') +end + + +-- love.graphics.printf +love.test.graphics.printf = function(test) + test:skipTest('test method needs writing') +end + -- love.graphics.rectangle love.test.graphics.rectangle = function(test) @@ -43,116 +136,985 @@ love.test.graphics.rectangle = function(test) black = {{1,1},{1,14},{3,1},{9,1},{3,14},{9,14},{11,1},{14,1},{11,14},{14,14}} } test:assertPixels(imgdata2, comparepixels, 'line') - -- -- write to save data for sanity checking - -- imgdata1:encode('png', 'love_test_graphics_rectangle_actual1.png') - -- imgdata2:encode('png', 'love_test_graphics_rectangle_actual2.png') - imgdata1:release() - imgdata2:release() end --- love.graphics.arc --- love.graphics.circle --- love.graphics.clear --- love.graphics.discard --- love.graphics.draw --- love.graphics.drawInstanced --- love.graphics.drawInstanced --- love.graphics.drawLayer --- love.graphics.ellipse --- love.graphics.flushBatch --- love.graphics.line --- love.graphics.points --- love.graphics.polygon --- love.graphics.present --- love.graphics.print --- love.graphics.printf --- love.graphics.rectangle + +-------------------------------------------------------------------------------- +-------------------------------------------------------------------------------- +--------------------------------OBJECT CREATION--------------------------------- +-------------------------------------------------------------------------------- +-------------------------------------------------------------------------------- + -- love.graphics.captureScreenshot +-- @NOTE could test this but not with current setup as we need to wait for the +-- draw frame to finish before we could assert the file was created +love.test.graphics.captureScreenshot = function(test) + test:skipTest('cant test this worked (easily)') +end + + -- love.graphics.newArrayImage +-- @NOTE this is just basic nil checking, full obj test are in objects.lua +love.test.graphics.newArrayImage = function(test) + test:assertObject(love.graphics.newArrayImage({ + 'resources/love.png', 'resources/love2.png', 'resources/love3.png' + })) +end + -- love.graphics.newCanvas +-- @NOTE this is just basic nil checking, full obj test are in objects.lua +love.test.graphics.newCanvas = function(test) + test:assertObject(love.graphics.newCanvas(16, 16, { + type = '2d', + format = 'normal', + readable = true, + msaa = 0, + dpiscale = 1, + mipmaps = 'none' + })) + test:assertObject(love.graphics.newCanvas(1000, 1000)) +end + + -- love.graphics.newCubeImage +-- @NOTE this is just basic nil checking, full obj test are in objects.lua +love.test.graphics.newCubeImage = function(test) + test:assertObject(love.graphics.newCubeImage('resources/cubemap.png', { + mipmaps = false, + linear = false + })) +end + + -- love.graphics.newFont +-- @NOTE this is just basic nil checking, full obj test are in objects.lua +love.test.graphics.newFont = function(test) + test:assertObject(love.graphics.newFont('resources/font.ttf')) + test:assertObject(love.graphics.newFont('resources/font.ttf', 8, "normal", 1)) +end + + -- love.graphics.newImage +-- @NOTE this is just basic nil checking, full obj test are in objects.lua +love.test.graphics.newImage = function(test) + test:assertObject(love.graphics.newImage('resources/love.png', { + mipmaps = false, + linear = false, + dpiscale = 1 + })) +end + + -- love.graphics.newImageFont +-- @NOTE this is just basic nil checking, full obj test are in objects.lua +love.test.graphics.newImageFont = function(test) + test:assertObject(love.graphics.newImageFont('resources/love.png', 'ABCD', 1)) +end + + -- love.graphics.newMesh +-- @NOTE this is just basic nil checking, full obj test are in objects.lua +love.test.graphics.newMesh = function(test) + test:assertObject(love.graphics.newMesh({{1, 1, 0, 0, 1, 1, 1, 1}}, 'fan', 'dynamic')) +end + + -- love.graphics.newParticleSystem +-- @NOTE this is just basic nil checking, full obj test are in objects.lua +love.test.graphics.newParticleSystem = function(test) + local imgdata = love.graphics.newImage('resources/love.png') + test:assertObject(love.graphics.newParticleSystem(imgdata, 1000)) +end + + -- love.graphics.newQuad +-- @NOTE this is just basic nil checking, full obj test are in objects.lua +love.test.graphics.newQuad = function(test) + local imgdata = love.graphics.newImage('resources/love.png') + test:assertObject(love.graphics.newQuad(0, 0, 16, 16, imgdata)) +end + + -- love.graphics.newShader +-- @NOTE this is just basic nil checking, full obj test are in objects.lua +love.test.graphics.newShader = function(test) + local pixelcode = 'vec4 effect(vec4 color, Image tex, vec2 texture_coords, vec2 screen_coords) { vec4 texturecolor = Texel(tex, texture_coords); return texturecolor * color;}' + local vertexcode = 'vec4 position(mat4 transform_projection, vec4 vertex_position) { return transform_projection * vertex_position; }' + test:assertObject(love.graphics.newShader(pixelcode, vertexcode)) +end + + -- love.graphics.newSpriteBatch +-- @NOTE this is just basic nil checking, full obj test are in objects.lua +love.test.graphics.newSpriteBatch = function(test) + local imgdata = love.graphics.newImage('resources/love.png') + test:assertObject(love.graphics.newSpriteBatch(imgdata, 1000)) +end + + -- love.graphics.newText +-- @NOTE this is just basic nil checking, full obj test are in objects.lua +love.test.graphics.newTextBatch = function(test) + local font = love.graphics.newFont('resources/font.ttf') + test:assertObject(love.graphics.newTextBatch(font, 'helloworld')) +end + + -- love.graphics.newVideo +-- @NOTE this is just basic nil checking, full obj test are in objects.lua +love.test.graphics.newVideo = function(test) + test:assertObject(love.graphics.newVideo('resources/sample.ogv', { + audio = false, + dpiscale = 1 + })) +end + + -- love.graphics.newVolumeImage --- love.graphics.setNewFont +-- @NOTE this is just basic nil checking, full obj test are in objects.lua +love.test.graphics.newVolumeImage = function(test) + test:assertObject(love.graphics.newVolumeImage({ + 'resources/love.png', 'resources/love2.png', 'resources/love3.png' + }, { + mipmaps = false, + linear = false + })) +end + + -- love.graphics.validateShader +love.test.graphics.validateShader = function(test) + local pixelcode = 'vec4 effect(vec4 color, Image tex, vec2 texture_coords, vec2 screen_coords) { vec4 texturecolor = Texel(tex, texture_coords); return texturecolor * color;}' + local vertexcode = 'vec4 position(mat4 transform_projection, vec4 vertex_position) { return transform_projection * vertex_position; }' + -- check made up code first + local status, _ = love.graphics.validateShader(true, 'nothing here', 'or here') + test:assertEquals(false, status, 'check invalid shader code') + -- check real code + status, _ = love.graphics.validateShader(true, pixelcode, vertexcode) + test:assertEquals(true, status, 'check valid shader code') +end + + +-------------------------------------------------------------------------------- +-------------------------------------------------------------------------------- +---------------------------------GRAPHICS STATE--------------------------------- +-------------------------------------------------------------------------------- +-------------------------------------------------------------------------------- + -- love.graphics.getBackgroundColor +love.test.graphics.getBackgroundColor = function(test) + -- check default bg is black + local r, g, b, a = love.graphics.getBackgroundColor() + test:assertEquals(0, r, 'check default background r') + test:assertEquals(0, g, 'check default background g') + test:assertEquals(0, b, 'check default background b') + test:assertEquals(1, a, 'check default background a') + -- check set value returns correctly + love.graphics.setBackgroundColor(1, 1, 1, 0) + r, g, b, a = love.graphics.getBackgroundColor() + test:assertEquals(1, r, 'check updated background r') + test:assertEquals(1, g, 'check updated background g') + test:assertEquals(1, b, 'check updated background b') + test:assertEquals(0, a, 'check updated background a') + love.graphics.setBackgroundColor(0, 0, 0, 1) -- reset +end + + -- love.graphics.getBlendMode +love.test.graphics.getBlendMode = function(test) + -- check default blend mode + local mode, alphamode = love.graphics.getBlendMode() + test:assertEquals('alpha', mode, 'check default blend mode') + test:assertEquals('alphamultiply', alphamode, 'check default alpha blend') + -- check set mode returns correctly + love.graphics.setBlendMode('add', 'premultiplied') + mode, alphamode = love.graphics.getBlendMode() + test:assertEquals('add', mode, 'check changed blend mode') + test:assertEquals('premultiplied', alphamode, 'check changed alpha blend') + love.graphics.setBlendMode('alpha', 'alphamultiply') -- reset +end + + -- love.graphics.getCanvas +love.test.graphics.getCanvas = function(test) + -- by default should be nil if drawing to real screen + test:assertEquals(nil, love.graphics.getCanvas(), 'check no canvas set') + -- should return not nil when we target a canvas + local canvas = love.graphics.newCanvas(16, 16) + love.graphics.setCanvas(canvas) + test:assertObject(love.graphics.getCanvas()) + love.graphics.setCanvas() +end + + -- love.graphics.getColor +love.test.graphics.getColor = function(test) + -- by default should be white + local r, g, b, a = love.graphics.getColor() + test:assertEquals(1, r, 'check default color r') + test:assertEquals(1, g, 'check default color g') + test:assertEquals(1, b, 'check default color b') + test:assertEquals(1, a, 'check default color a') + -- check set color is returned correctly + love.graphics.setColor(0, 0, 0, 0) + r, g, b, a = love.graphics.getColor() + test:assertEquals(0, r, 'check changed color r') + test:assertEquals(0, g, 'check changed color g') + test:assertEquals(0, b, 'check changed color b') + test:assertEquals(0, a, 'check changed color a') + love.graphics.setColor(1, 1, 1, 1) -- reset +end + + -- love.graphics.getColorMask +love.test.graphics.getColorMask = function(test) + -- by default should all be active + local r, g, b, a = love.graphics.getColorMask() + test:assertEquals(true, r, 'check default color mask r') + test:assertEquals(true, g, 'check default color mask g') + test:assertEquals(true, b, 'check default color mask b') + test:assertEquals(true, a, 'check default color mask a') + -- check set color mask is returned correctly + love.graphics.setColorMask(false, false, true, false) + r, g, b, a = love.graphics.getColorMask() + test:assertEquals(false, r, 'check changed color mask r') + test:assertEquals(false, g, 'check changed color mask g') + test:assertEquals(true, b, 'check changed color mask b') + test:assertEquals(false, a, 'check changed color mask a') + love.graphics.setColorMask(true, true, true, true) -- reset +end + + -- love.graphics.getDefaultFilter +love.test.graphics.getDefaultFilter = function(test) + -- we set this already for testsuite so we know what it should be + local min, mag, anisotropy = love.graphics.getDefaultFilter() + test:assertEquals('nearest', min, 'check default filter min') + test:assertEquals('nearest', mag, 'check default filter mag') + test:assertEquals(1, anisotropy, 'check default filter mag') +end + + -- love.graphics.getDepthMode +love.test.graphics.getDepthMode = function(test) + -- by default should be always/write + local comparemode, write = love.graphics.getDepthMode() + test:assertEquals('always', comparemode, 'check default compare depth') + test:assertEquals(false, write, 'check default depth buffer write') +end + + -- love.graphics.getFont +love.test.graphics.getFont = function(test) + test:assertObject(love.graphics.getFont()) +end + + -- love.graphics.getFrontFaceWinding +love.test.graphics.getFrontFaceWinding = function(test) + -- check default winding + test:assertEquals('ccw', love.graphics.getFrontFaceWinding()) + -- check setting value changes it correctly + love.graphics.setFrontFaceWinding('cw') + test:assertEquals('cw', love.graphics.getFrontFaceWinding()) + love.graphics.setFrontFaceWinding('ccw') -- reset +end + + -- love.graphics.getLineJoin +love.test.graphics.getLineJoin = function(test) + -- check default line join + test:assertEquals('miter', love.graphics.getLineJoin()) + -- check set value returned correctly + love.graphics.setLineJoin('none') + test:assertEquals('none', love.graphics.getLineJoin()) + love.graphics.setLineJoin('miter') -- reset +end + + -- love.graphics.getLineStyle +love.test.graphics.getLineStyle = function(test) + -- we know this should be as testsuite sets it! + test:assertEquals('rough', love.graphics.getLineStyle()) + -- check set value returned correctly + love.graphics.setLineStyle('smooth') + test:assertEquals('smooth', love.graphics.getLineStyle()) + love.graphics.setLineStyle('rough') -- reset +end + + -- love.graphics.getLineWidth +love.test.graphics.getLineWidth = function(test) + -- we know this should be as testsuite sets it! + test:assertEquals(1, love.graphics.getLineWidth()) + -- check set value returned correctly + love.graphics.setLineWidth(10) + test:assertEquals(10, love.graphics.getLineWidth()) + love.graphics.setLineWidth(1) -- reset +end + + -- love.graphics.getMeshCullMode +love.test.graphics.getMeshCullMode = function(test) + -- get default mesh culling + test:assertEquals('none', love.graphics.getMeshCullMode()) + -- check set value returned correctly + love.graphics.setMeshCullMode('front') + test:assertEquals('front', love.graphics.getMeshCullMode()) + love.graphics.setMeshCullMode('back') -- reset +end + + -- love.graphics.getPointSize +love.test.graphics.getPointSize = function(test) + -- get default point size + test:assertEquals(1, love.graphics.getPointSize()) + -- check set value returned correctly + love.graphics.setPointSize(10) + test:assertEquals(10, love.graphics.getPointSize()) + love.graphics.setPointSize(1) -- reset +end + + -- love.graphics.getScissor +love.test.graphics.getScissor = function(test) + -- should be no scissor atm + local x, y, w, h = love.graphics.getScissor() + test:assertEquals(nil, x, 'check no scissor') + test:assertEquals(nil, y, 'check no scissor') + test:assertEquals(nil, w, 'check no scissor') + test:assertEquals(nil, h, 'check no scissor') + -- check set value returned correctly + love.graphics.setScissor(0, 0, 16, 16) + x, y, w, h = love.graphics.getScissor() + test:assertEquals(0, x, 'check scissor set') + test:assertEquals(0, y, 'check scissor set') + test:assertEquals(16, w, 'check scissor set') + test:assertEquals(16, h, 'check scissor set') + love.graphics.setScissor() -- reset +end + + -- love.graphics.getShader +love.test.graphics.getShader = function(test) + -- should be no shader active + test:assertEquals(nil, love.graphics.getShader(), 'check no active shader') +end + + -- love.graphics.getStackDepth --- love.graphics.getStencilTest +love.test.graphics.getStackDepth = function(test) + -- by default should be none + test:assertEquals(0, love.graphics.getStackDepth(), 'check no transforms in stack') + -- now add 3 + love.graphics.push() + love.graphics.push() + love.graphics.push() + test:assertEquals(3, love.graphics.getStackDepth(), 'check 3 transforms in stack') + -- now remove 2 + love.graphics.pop() + love.graphics.pop() + test:assertEquals(1, love.graphics.getStackDepth(), 'check 1 transforms in stack') + -- now back to 0 + love.graphics.pop() + test:assertEquals(0, love.graphics.getStackDepth(), 'check no transforms in stack') +end + + +-- love.graphics.getStencilMode +love.test.graphics.getStencilMode = function(test) + -- check default vals + local action, comparemode, value = love.graphics.getStencilMode( ) + test:assertEquals('keep', action, 'check default stencil action') + test:assertEquals('always', comparemode, 'check default stencil compare') + test:assertEquals(0, value, 'check default stencil value') + -- check set stencil values is returned + love.graphics.setStencilMode('replace', 'less', 255) + local action, comparemode, value = love.graphics.getStencilMode() + test:assertEquals('replace', action, 'check changed stencil action') + test:assertEquals('less', comparemode, 'check changed stencil compare') + test:assertEquals(255, value, 'check changed stencil value') + love.graphics.setStencilMode() -- reset +end + + -- love.graphics.intersectScissor +love.test.graphics.intersectScissor = function(test) + -- make a scissor for the left half, then interset to make the top half + -- then we should be able to fill the canvas with red and only top 4x4 is filled + local canvas = love.graphics.newCanvas(16, 16) + love.graphics.setCanvas(canvas) + love.graphics.clear(0, 0, 0, 1) + 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, 1, 1, 1) + love.graphics.setScissor() + love.graphics.setCanvas() + local imgdata = love.graphics.readbackTexture(canvas, {16, 0, 0, 0, 16, 16}) + test:assertPixels(imgdata, { + red = {{0,0},{3,3}}, + black ={{4,0},{0,4},{4,4}} + }, 'intersect scissor') +end + + -- love.graphics.isActive +love.test.graphics.isActive = function(test) + test:assertEquals(true, love.graphics.isActive(), 'check graphics is active') -- i mean if you got this far +end + + -- love.graphics.isGammaCorrect --- love.graphics.isSupported +love.test.graphics.isGammaCorrect = function(test) + -- we know the config so know this is false + test:assertEquals(false, love.graphics.isGammaCorrect(), 'check gamma correct false') +end + + -- love.graphics.isWireframe +love.test.graphics.isWireframe = function(test) + -- check off by default + test:assertEquals(false, love.graphics.isWireframe(), 'check no wireframe by default') + -- check on when enabled + love.graphics.setWireframe(true) + test:assertEquals(true, love.graphics.isWireframe(), 'check wireframe is set') + love.graphics.setWireframe(false) -- reset +end + + -- love.graphics.reset +love.test.graphics.reset = function(test) + -- reset should reset current canvas and any colors/scissor + local canvas = love.graphics.newCanvas(16, 16) + love.graphics.setBackgroundColor(0, 0, 1, 1) + love.graphics.setColor(0, 1, 0, 1) + love.graphics.setCanvas(canvas) + love.graphics.reset() + local r, g, b, a = love.graphics.getBackgroundColor() + test:assertEquals(1, r+g+b+a, 'check background reset') + r, g, b, a = love.graphics.getColor() + test:assertEquals(4, r+g+b+a, 'check color reset') + test:assertEquals(nil, love.graphics.getCanvas(), 'check canvas reset') +end + + -- love.graphics.setBackgroundColor +love.test.graphics.setBackgroundColor = function(test) + -- check background is set + love.graphics.setBackgroundColor(1, 0, 0, 1) + local r, g, b, a = love.graphics.getBackgroundColor() + test:assertEquals(1, r, 'check set bg r') + test:assertEquals(0, g, 'check set bg g') + test:assertEquals(0, b, 'check set bg b') + test:assertEquals(1, a, 'check set bg a') +end + + -- love.graphics.setBlendMode +love.test.graphics.setBlendMode = function(test) + -- set mode, write to canvas, check output + test:skipTest('test method needs writing') +end + + -- love.graphics.setCanvas +love.test.graphics.setCanvas = function(test) + -- make 2 canvas, set to each, draw one to the other, check output + test:skipTest('test method needs writing') +end + + -- love.graphics.setColor +love.test.graphics.setColor = function(test) + -- set colors, draw rect, check color + test:skipTest('test method needs writing') +end + + -- love.graphics.setColorMask +love.test.graphics.setColorMask = function(test) + -- set mask, draw stuff, check output pixels + test:skipTest('test method needs writing') +end + + -- love.graphics.setDefaultFilter +love.test.graphics.setDefaultFilter = function(test) + -- check setting filter val works + love.graphics.setDefaultFilter('linear', 'linear', 1) + local min, mag, anisotropy = love.graphics.getDefaultFilter() + test:assertEquals('linear', min, 'check default filter min') + test:assertEquals('linear', mag, 'check default filter mag') + test:assertEquals(1, anisotropy, 'check default filter mag') + love.graphics.setDefaultFilter('nearest', 'nearest', 1) -- reset +end + + -- love.graphics.setDepthMode +love.test.graphics.setDepthMode = function(test) + test:skipTest('test method needs writing') +end + + -- love.graphics.setFont +love.test.graphics.setFont = function(test) + test:skipTest('test method needs writing') +end + + -- love.graphics.setFrontFaceWinding +love.test.graphics.setFrontFaceWinding = function(test) + test:skipTest('test method needs writing') +end + + -- love.graphics.setLineJoin +love.test.graphics.setLineJoin = function(test) + test:skipTest('test method needs writing') +end + + -- love.graphics.setLineStyle +love.test.graphics.setLineStyle = function(test) + test:skipTest('test method needs writing') +end + + -- love.graphics.setLineWidth +love.test.graphics.setLineWidth = function(test) + test:skipTest('test method needs writing') +end + + -- love.graphics.setMeshCullMode --- love.graphics.setPointStyle +love.test.graphics.setMeshCullMode = function(test) + test:skipTest('test method needs writing') +end + + -- love.graphics.setScissor +love.test.graphics.setScissor = function(test) + test:skipTest('test method needs writing') +end + + -- love.graphics.setShader +love.test.graphics.setShader = function(test) + test:skipTest('test method needs writing') +end + + -- love.graphics.setStencilTest +love.test.graphics.setStencilMode = function(test) + test:skipTest('test method needs writing') +end + + -- love.graphics.setWireframe +love.test.graphics.setWireframe = function(test) + test:skipTest('test method needs writing') +end + + +-------------------------------------------------------------------------------- +-------------------------------------------------------------------------------- +-------------------------------COORDINATE SYSTEM-------------------------------- +-------------------------------------------------------------------------------- +-------------------------------------------------------------------------------- + -- love.graphics.applyTransform +love.test.graphics.applyTransform = function(test) + -- use transform object to translate the drawn rectangle + local transform = love.math.newTransform() + transform:translate(10, 0) + 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.applyTransform(transform) + love.graphics.rectangle('fill', 0, 0, 1, 1) + 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 = {{10, 0}} }, 'apply transform 10') +end + + -- love.graphics.inverseTransformPoint +love.test.graphics.inverseTransformPoint = function(test) + -- start with 0, 0 + local sx, sy = love.graphics.inverseTransformPoint(0, 0) + test:assertEquals(0, sx, 'check starting x is 0') + test:assertEquals(0, sy, 'check starting y is 0') + -- check translation effects the point + love.graphics.translate(1, 5) + sx, sy = love.graphics.inverseTransformPoint(1, 5) + test:assertEquals(0, sx, 'check transformed x is 0') + test:assertEquals(0, sy, 'check transformed y is 0') + love.graphics.origin() +end + + -- love.graphics.origin +love.test.graphics.origin = function(test) + -- if we do some translations and scaling + -- using .origin() should reset it all and draw the pixel at 0,0 + local canvas = love.graphics.newCanvas(16, 16) + love.graphics.setCanvas(canvas) + love.graphics.clear(0, 0, 0, 1) + love.graphics.origin() + love.graphics.translate(10, 10) + love.graphics.scale(1, 1) + love.graphics.shear(20, 20) + love.graphics.origin() + love.graphics.setColor(1, 0, 0, 1) + love.graphics.rectangle('fill', 0, 0, 1, 1) + 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}} }, 'origin check') +end + + -- love.graphics.pop +love.test.graphics.pop = function(test) + -- if we push at the start, and then run a pop + -- it should reset it all and draw the pixel at 0,0 + local canvas = love.graphics.newCanvas(16, 16) + love.graphics.setCanvas(canvas) + love.graphics.clear(0, 0, 0, 1) + love.graphics.push() + love.graphics.translate(10, 10) + love.graphics.scale(1, 1) + love.graphics.shear(20, 20) + love.graphics.pop() + love.graphics.setColor(1, 0, 0, 1) + love.graphics.rectangle('fill', 0, 0, 1, 1) + 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}} }, 'pop 1') +end + + -- love.graphics.push +love.test.graphics.push = function(test) + -- if we push at the start, do some stuff, then another push + -- 1 pop should only go back 1 push and draw the pixel at 1, 1 + local canvas = love.graphics.newCanvas(16, 16) + love.graphics.setCanvas(canvas) + love.graphics.clear(0, 0, 0, 1) + love.graphics.push() + love.graphics.scale(1, 1) + love.graphics.shear(20, 20) + love.graphics.push() + love.graphics.translate(1, 1) + love.graphics.pop() + love.graphics.setColor(1, 0, 0, 1) + love.graphics.rectangle('fill', 0, 0, 1, 1) + 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, 1}} }, 'push 1') +end + + -- love.graphics.replaceTransform +love.test.graphics.replaceTransform = function(test) + -- if use transform object to translate + -- set some normal transforms first which should get overwritten + local transform = love.math.newTransform() + transform:translate(10, 0) + 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.scale(2, 2) + love.graphics.translate(10, 10) + love.graphics.replaceTransform(transform) + love.graphics.rectangle('fill', 0, 0, 1, 1) + 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 = {{10, 0}} }, 'replace transform 10') +end + + -- love.graphics.rotate +love.test.graphics.rotate = function(test) + -- starting at 0,0, we rotate by 90deg and then draw + -- we can then check the drawn rectangle is rotated + 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.translate(4, 0) + love.graphics.rotate(90 * (math.pi/180)) + love.graphics.rectangle('fill', 0, 0, 4, 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, { red = {{0,0},{3,0},{3,3},{0,3}} }, 'rotate 90') + imgdata:encode('png', 'rotate.png') +end + + -- love.graphics.scale +love.test.graphics.scale = function(test) + -- starting at 0,0, we scale by 4x and then draw + -- we can then check the drawn rectangle covers the whole canvas + 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.scale(4, 4) + love.graphics.rectangle('fill', 0, 0, 4, 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, { red = {{1,1},{1,15},{15,1},{15,15}} }, 'scale 4x') +end + + -- love.graphics.shear +love.test.graphics.shear = function(test) + -- starting at 0,0, we shear by 2x and then draw + -- we can then check the drawn rectangle has moved over + local canvas = love.graphics.newCanvas(16, 16) + love.graphics.setCanvas(canvas) + love.graphics.clear(0, 0, 0, 1) + love.graphics.origin() + love.graphics.setColor(1, 0, 0, 1) + love.graphics.shear(2, 0) + love.graphics.rectangle('fill', 0, 0, 4, 4) + 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, { red = {{1,0},{4,0},{7,3},{10,3}} }, 'shear x') + -- same again at 0,0, we shear by 2y and then draw + -- we can then check the drawn rectangle has moved down + love.graphics.setCanvas(canvas) + love.graphics.clear(0, 0, 0, 1) + love.graphics.origin() + love.graphics.setColor(1, 0, 0, 1) + love.graphics.shear(0, 2) + love.graphics.rectangle('fill', 0, 0, 4, 4) + 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, { red = { {0,1},{0,4},{3,7},{3,10}} }, 'shear y') +end + + -- love.graphics.transformPoint +love.test.graphics.transformPoint = function(test) + -- start with 0, 0 + local sx, sy = love.graphics.transformPoint(0, 0) + test:assertEquals(0, sx, 'check starting x is 0') + test:assertEquals(0, sy, 'check starting y is 0') + -- check translation effects the point + love.graphics.translate(1, 5) + sx, sy = love.graphics.transformPoint(0, 0) + test:assertEquals(1, sx, 'check transformed x is 0') + test:assertEquals(5, sy, 'check transformed y is 10') +end + + -- love.graphics.translate +love.test.graphics.translate = function(test) + -- starting at 0,0, we translate 4 times and draw a pixel at each point + -- we can then check the 4 points are now red + 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.translate(5, 0) + love.graphics.rectangle('fill', 0, 0, 1, 1) + love.graphics.translate(0, 5) + love.graphics.rectangle('fill', 0, 0, 1, 1) + love.graphics.translate(-5, 0) + love.graphics.rectangle('fill', 0, 0, 1, 1) + love.graphics.translate(0, -5) + love.graphics.rectangle('fill', 0, 0, 1, 1) + 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 = {{5,0},{0,5},{5,5},{0,0}} }, 'translate 4x') +end + + +-------------------------------------------------------------------------------- +-------------------------------------------------------------------------------- +-------------------------------------WINDOW------------------------------------- +-------------------------------------------------------------------------------- +-------------------------------------------------------------------------------- + -- love.graphics.getDPIScale --- love.graphics.getDimensions --- love.graphics.getHeight --- love.graphics.getPixelDimensions --- love.graphics.getPixelHeight --- love.graphics.getPixelWidth --- love.graphics.getWidth +-- @NOTE hardware dependent so can't check result +love.test.graphics.getDPIScale = function(test) + test:assertNotNil(love.graphics.getDPIScale()) +end + + +-- love.graphics.getDimensions +love.test.graphics.getDimensions = function(test) + -- check graphics dimensions match window dimensions + local gwidth, gheight = love.graphics.getDimensions() + local wwidth, wheight, _ = love.window.getMode() + test:assertEquals(wwidth, gwidth, 'check graphics dimension w matches window w') + test:assertEquals(wheight, gheight, 'check graphics dimension h matches window h') +end + + +-- love.graphics.getHeight +love.test.graphics.getHeight = function(test) + -- check graphics height match window height + local wwidth, wheight, _ = love.window.getMode() + test:assertEquals(wheight, love.graphics.getHeight(), 'check graphics h matches window h') +end + + +-- love.graphics.getPixelDimensions +love.test.graphics.getPixelDimensions = function(test) + -- check graphics dimensions match window dimensions relative to dpi + local dpi = love.graphics.getDPIScale() + local gwidth, gheight = love.graphics.getPixelDimensions() + local wwidth, wheight, _ = love.window.getMode() + test:assertEquals(wwidth, gwidth/dpi, 'check graphics pixel dpi w matches window w') + test:assertEquals(wheight, gheight/dpi, 'check graphics pixel dpi h matches window h') +end + + +-- love.graphics.getPixelHeight +love.test.graphics.getPixelHeight = function(test) + -- check graphics height match window height relative to dpi + local dpi = love.graphics.getDPIScale() + local wwidth, wheight, _ = love.window.getMode() + test:assertEquals(wheight,love.graphics.getPixelHeight()/dpi, 'check graphics pixel dpi h matches window h') +end + + +-- love.graphics.getPixelWidth +love.test.graphics.getPixelWidth = function(test) + -- check graphics width match window width relative to dpi + local dpi = love.graphics.getDPIScale() + local wwidth, wheight, _ = love.window.getMode() + test:assertEquals(wwidth, love.graphics.getWidth()/dpi, 'check graphics pixel dpi w matches window w') +end + + +-- love.graphics.getWidth +love.test.graphics.getWidth = function(test) + -- check graphics width match window width + local wwidth, wheight, _ = love.window.getMode() + test:assertEquals(wwidth, love.graphics.getWidth(), 'check graphics w matches window w') +end + + +-------------------------------------------------------------------------------- +-------------------------------------------------------------------------------- +-------------------------------SYSTEM INFORMATION------------------------------- +-------------------------------------------------------------------------------- +-------------------------------------------------------------------------------- + + +-- love.graphics.getTextureFormats +love.test.graphics.getTextureFormats = function(test) + local formats = { + 'hdr', 'r8i', 'r8ui', 'r16i', 'r16ui', 'r32i', 'r32ui', 'rg8i', 'rg8ui', + 'rg16i', 'rg16ui', 'rg32i', 'rg32ui', 'bgra8', 'r8', 'rgba8i', 'rgba8ui', + 'rgba16i', 'rg8', 'rgba32i', 'rgba32ui', 'rgba8', 'DXT1', 'r16', 'DXT5', + 'rg16', 'BC4s', 'rgba16', 'BC5s', 'r16f', 'BC6hs', 'BC7', 'PVR1rgb2', + 'rg16f', 'PVR1rgba2', 'rgba16f', 'ETC1', 'r32f', 'ETC2rgba', 'rg32f', + 'EACr', 'rgba32f', 'EACrg', 'rgba4', 'ASTC4x4', 'ASTC5x4', 'rgb5a1', + 'ASTC6x5', 'rgb565', 'ASTC8x5', 'ASTC8x6', 'rgb10a2', 'ASTC10x5', + 'rg11b10f', 'ASTC10x8', 'ASTC10x10', 'ASTC12x10', 'ASTC12x12', 'normal', + 'srgba8', 'la8', 'ASTC10x6', 'ASTC8x8', 'ASTC6x6', 'ASTC5x5', 'EACrgs', + 'EACrs', 'ETC2rgba1', 'ETC2rgb', 'PVR1rgba4', 'PVR1rgb4', 'BC6h', + 'BC5', 'BC4', 'DXT3', 'stencil8', 'rgba16ui', 'bgra8srgb' + } + local supported = love.graphics.getTextureFormats({ canvas = true }) + test:assertNotNil(supported) + for f=1,#formats do + test:assertNotEquals(nil, supported[formats[f] ], 'expected a key for format: ' .. formats[f]) + end +end + --- love.graphics.getCanvasformats --- love.graphics.getImageFormats -- love.graphics.getRendererInfo +-- @NOTE hardware dependent so best can do is nil checking +love.test.graphics.getRendererInfo = function(test) + local name, version, vendor, device = love.graphics.getRendererInfo() + test:assertNotNil(name) + test:assertNotNil(version) + test:assertNotNil(vendor) + test:assertNotNil(device) +end + + -- love.graphics.getStats +-- @NOTE cant really predict some of these so just nil check for most +love.test.graphics.getStats = function(test) + local stattypes = { + 'drawcalls', 'canvasswitches', 'texturememory', 'shaderswitches', + 'drawcallsbatched', 'textures', 'fonts' + } + local stats = love.graphics.getStats() + for s=1,#stattypes do + test:assertNotEquals(nil, stats[stattypes[s] ], 'expected a key for stat: ' .. stattypes[s]) + end +end + + -- love.graphics.getSupported +love.test.graphics.getSupported = function(test) + -- cant check values as hardware dependent but we can check the keys in the + -- table match what the documentation lists + local gfs = { + 'clampzero', 'lighten', 'glsl3', 'instancing', 'fullnpot', + 'pixelshaderhighp', 'shaderderivatives', 'indirectdraw', 'mipmaprange', + 'copyrendertargettobuffer', 'copytexturetobuffer', 'copybuffer', + 'indexbuffer32bit', 'multirendertargetformats', 'clampone', 'blendminmax', + 'glsl4' + } + local features = love.graphics.getSupported() + for g=1,#gfs do + test:assertNotEquals(nil, features[gfs[g] ], 'expected a key for graphic feature: ' .. gfs[g]) + end +end + + -- love.graphics.getSystemLimits --- love.graphics.getTextureTypes \ No newline at end of file +love.test.graphics.getSystemLimits = function(test) + -- cant check values as hardware dependent but we can check the keys in the + -- table match what the documentation lists + local glimits = { + 'texelbuffersize', 'shaderstoragebuffersize', 'threadgroupsx', + 'threadgroupsy', 'pointsize', 'texturesize', 'texturelayers', 'volumetexturesize', + 'cubetexturesize', 'anisotropy', 'texturemsaa', 'rendertargets', 'threadgroupsz' + } + local limits = love.graphics.getSystemLimits() + for g=1,#glimits do + test:assertNotEquals(nil, limits[glimits[g] ], 'expected a key for system limit: ' .. glimits[g]) + end +end + + +-- love.graphics.getTextureTypes +love.test.graphics.getTextureTypes = function(test) + -- cant check values as hardware dependent but we can check the keys in the + -- table match what the documentation lists + local ttypes = { + '2d', 'array', 'cube', 'volume' + } + local types = love.graphics.getTextureTypes() + for t=1,#ttypes do + test:assertNotEquals(nil, types[ttypes[t] ], 'expected a key for texture type: ' .. ttypes[t]) + end +end diff --git a/testing/tests/image.lua b/testing/tests/image.lua index 357bc60be..e0a71d492 100644 --- a/testing/tests/image.lua +++ b/testing/tests/image.lua @@ -4,28 +4,23 @@ -- love.image.isCompressed -- @NOTE really we need to test each of the files listed here: -- https://love2d.org/wiki/CompressedImageFormat +-- also need to be platform dependent (e.g. dxt not suppored on phones) love.test.image.isCompressed = function(test) - local compressed = love.image.isCompressed('resources/love.dxt1') - test:assertEquals(true, compressed, 'check dxt1 valid compressed image') + test:assertEquals(true, love.image.isCompressed('resources/love.dxt1'), + 'check dxt1 valid compressed image') end -- love.image.newCompressedData -- @NOTE this is just basic nil checking, full obj test are in objects.lua love.test.image.newCompressedData = function(test) - local imgdata = love.image.newCompressedData('resources/love.dxt1') - test:assertObject(imgdata) - imgdata:release() + test:assertObject(love.image.newCompressedData('resources/love.dxt1')) end -- love.image.newImageData -- @NOTE this is just basic nil checking, full obj test are in objects.lua love.test.image.newImageData = function(test) - local imgdata = love.image.newImageData('resources/love.png') - local rawdata = love.image.newImageData(16, 16, 'rgba8', nil) - test:assertObject(imgdata) - test:assertObject(rawdata) - imgdata:release() - rawdata:release() -end \ No newline at end of file + test:assertObject(love.image.newImageData('resources/love.png')) + test:assertObject(love.image.newImageData(16, 16, 'rgba8', nil)) +end diff --git a/testing/tests/math.lua b/testing/tests/math.lua index 626692c2d..51e915728 100644 --- a/testing/tests/math.lua +++ b/testing/tests/math.lua @@ -3,16 +3,19 @@ -- love.math.colorFromBytes love.test.math.colorFromBytes = function(test) + -- check random value local r, g, b, a = love.math.colorFromBytes(51, 51, 51, 51) test:assertEquals(r, 0.2, 'check r from bytes') test:assertEquals(g, 0.2, 'check g from bytes') test:assertEquals(b, 0.2, 'check b from bytes') test:assertEquals(a, 0.2, 'check a from bytes') + -- check "max" value r, g, b, a = love.math.colorFromBytes(255, 255, 255, 255) test:assertEquals(r, 1, 'check r from bytes') test:assertEquals(g, 1, 'check g from bytes') test:assertEquals(b, 1, 'check b from bytes') test:assertEquals(a, 1, 'check a from bytes') + -- check "min" value r, g, b, a = love.math.colorFromBytes(0, 0, 0, 0) test:assertEquals(r, 0, 'check r from bytes') test:assertEquals(g, 0, 'check g from bytes') @@ -23,16 +26,19 @@ end -- love.math.colorToBytes love.test.math.colorToBytes = function(test) + -- check random value local r, g, b, a = love.math.colorToBytes(0.2, 0.2, 0.2, 0.2) test:assertEquals(r, 51, 'check bytes from r') test:assertEquals(g, 51, 'check bytes from g') test:assertEquals(b, 51, 'check bytes from b') test:assertEquals(a, 51, 'check bytes from a') + -- check "max" value r, g, b, a = love.math.colorToBytes(1, 1, 1, 1) test:assertEquals(r, 255, 'check bytes from r') test:assertEquals(g, 255, 'check bytes from g') test:assertEquals(b, 255, 'check bytes from b') test:assertEquals(a, 255, 'check bytes from a') + -- check "min" value r, g, b, a = love.math.colorToBytes(0, 0, 0, 0) test:assertEquals(r, 0, 'check bytes from r') test:assertEquals(g, 0, 'check bytes from g') @@ -65,8 +71,7 @@ end -- love.math.getRandomState love.test.math.getRandomState = function(test) - local state = love.math.getRandomState() - test:assertNotEquals(nil, state, 'check not nil') + test:assertNotNil(love.math.getRandomState()) end @@ -95,49 +100,69 @@ end -- love.math.newBezierCurve -- @NOTE this is just basic nil checking, full obj test are in objects.lua love.test.math.newBezierCurve = function(test) - local curve = love.math.newBezierCurve({0, 0, 0, 1, 1, 1, 2, 1}) - test:assertObject(curve) - curve:release() + test:assertObject(love.math.newBezierCurve({0, 0, 0, 1, 1, 1, 2, 1})) end -- love.math.newRandomGenerator -- @NOTE this is just basic nil checking, full obj test are in objects.lua love.test.math.newRandomGenerator = function(test) - local rangen = love.math.newRandomGenerator() - test:assertObject(rangen) - rangen:release() + test:assertObject(love.math.newRandomGenerator()) end -- love.math.newTransform -- @NOTE this is just basic nil checking, full obj test are in objects.lua love.test.math.newTransform = function(test) - local transform = love.math.newTransform() - test:assertObject(transform) - transform:release() + test:assertObject(love.math.newTransform()) end --- love.math.noise -love.test.math.noise = function(test) - local noise1 = love.math.noise(100) - local noise2 = love.math.noise(1, 10) - local noise3 = love.math.noise(1043, 31.123, 999) - local noise4 = love.math.noise(99.222, 10067, 8, 1843) +-- love.math.perlinNoise +love.test.math.perlinNoise = function(test) + -- check some noise values + -- output should be consistent if given the same input + local noise1 = love.math.perlinNoise(100) + local noise2 = love.math.perlinNoise(1, 10) + local noise3 = love.math.perlinNoise(1043, 31.123, 999) + local noise4 = love.math.perlinNoise(99.222, 10067, 8, 1843) + -- rounded to avoid floating point issues test:assertEquals(50000, math.floor(noise1*100000), 'check noise 1 dimension') - test:assertEquals(47863, math.floor(noise2*100000), 'check noise 2 dimensions') + test:assertEquals(50000, math.floor(noise2*100000), 'check noise 2 dimensions') test:assertEquals(56297, math.floor(noise3*100000), 'check noise 3 dimensions') test:assertEquals(52579, math.floor(noise4*100000), 'check noise 4 dimensions') end +-- love.math.simplexNoise +love.test.math.simplexNoise = function(test) + -- check some noise values + -- output should be consistent if given the same input + local noise1 = love.math.simplexNoise(100) + local noise2 = love.math.simplexNoise(1, 10) + local noise3 = love.math.simplexNoise(1043, 31.123, 999) + local noise4 = love.math.simplexNoise(99.222, 10067, 8, 1843) + -- rounded to avoid floating point issues + test:assertEquals(50000, math.floor(noise1*100000), 'check noise 1 dimension') + test:assertEquals(47863, math.floor(noise2*100000), 'check noise 2 dimensions') + test:assertEquals(26440, math.floor(noise3*100000), 'check noise 3 dimensions') + test:assertEquals(53360, math.floor(noise4*100000), 'check noise 4 dimensions') +end + + -- love.math.random love.test.math.random = function(test) - local random = love.math.random(10) - local randomminmax = love.math.random(5, 100) - test:assertRange(random, 1, 10, 'check within 1 - 10') - test:assertRange(randomminmax, 5, 100, 'check within 5 - 100') + -- check some random ranges + test:assertRange(love.math.random(10), 1, 10, 'check within 1 - 10') + test:assertRange(love.math.random(10), 1, 10, 'check within 1 - 10') + test:assertRange(love.math.random(10), 1, 10, 'check within 1 - 10') + test:assertRange(love.math.random(10), 1, 10, 'check within 1 - 10') + test:assertRange(love.math.random(10), 1, 10, 'check within 1 - 10') + test:assertRange(love.math.random(5, 100), 5, 100, 'check within 5 - 100') + test:assertRange(love.math.random(5, 100), 5, 100, 'check within 5 - 100') + test:assertRange(love.math.random(5, 100), 5, 100, 'check within 5 - 100') + test:assertRange(love.math.random(5, 100), 5, 100, 'check within 5 - 100') + test:assertRange(love.math.random(5, 100), 5, 100, 'check within 5 - 100') end @@ -145,8 +170,7 @@ end -- @NOTE i dont _really_ get the range expected based on stddev + mean -- so feel free to change to be more accurate love.test.math.randomNormal = function(test) - local random = love.math.randomNormal(1, 0) - test:assertRange(random, -3, 3, 'check within -3 - 3') + test:assertRange(love.math.randomNormal(1, 0), -3, 3, 'check within -3 - 3') end @@ -162,6 +186,7 @@ end -- love.math.setRandomState love.test.math.setRandomState = function(test) + -- check setting state matches value returned local rs1 = love.math.getRandomState() love.math.setRandomState(rs1) local rs2 = love.math.getRandomState() @@ -175,4 +200,4 @@ love.test.math.triangulate = function(test) local triangles2 = love.math.triangulate({1, 2, 2, 4, 3, 4, 2, 1, 3, 1}) -- weird shape test:assertEquals(3, #triangles1, 'check polygon triangles') test:assertEquals(3, #triangles2, 'check polygon triangles') -end \ No newline at end of file +end diff --git a/testing/tests/objects.lua b/testing/tests/objects.lua index cf39ed5c8..6ccd9dae0 100644 --- a/testing/tests/objects.lua +++ b/testing/tests/objects.lua @@ -45,16 +45,18 @@ love.test.objects.File = function(test) -- @NOTE think I'm just not understanding how this is supposed to work? -- I thought if buffering is enabled then nothing should get written until -- buffer overflows? - file1:open('a') - ok, err = file1:setBuffer('full', 10000) - test:assertEquals(true, ok) - test:assertEquals('full', file1:getBuffer()) - file1:write('morecontent') - file1:close() - file1:open('r') - contents, size = file1:read() - test:assertEquals('helloworld', contents, 'check buffered content wasnt written') - file1:close() + -- file1:open('a') + -- ok, err = file1:setBuffer('full', 10000) + -- test:assertEquals(true, ok) + -- test:assertEquals('full', file1:getBuffer()) + -- file1:write('morecontent') + -- file1:close() + -- file1:open('r') + -- contents, size = file1:read() + -- test:assertEquals('helloworld', contents, 'check buffered content wasnt written') + -- file1:close() + + -- @NOTE :close() commits buffer content so need to check before not after -- test buffering and flushing file1:open('w') @@ -83,8 +85,6 @@ love.test.objects.File = function(test) test:assertEquals(counter, 15) file1:close() - file1:release() - end @@ -172,4 +172,4 @@ end -- Shader -- SpriteBatch -- Text --- Video \ No newline at end of file +-- Video diff --git a/testing/tests/physics.lua b/testing/tests/physics.lua index 8431f1df6..87b99da3b 100644 --- a/testing/tests/physics.lua +++ b/testing/tests/physics.lua @@ -3,27 +3,21 @@ -- love.physics.getDistance love.test.physics.getDistance = function(test) - -- setup + -- 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) - -- test + -- check distance between them test:assertEquals(647106, math.floor(love.physics.getDistance(fixture1, fixture2)*100000), 'check distance matches') - -- cleanup - fixture1:release() - fixture2:release() - body:release() - world:release() - shape1:release() - shape2:release() end -- love.physics.getMeter love.test.physics.getMeter = function(test) + -- check value set is returned love.physics.setMeter(30) test:assertEquals(30, love.physics.getMeter(), 'check meter matches') end @@ -32,50 +26,34 @@ end -- love.physics.newBody -- @NOTE this is just basic nil checking, full obj test are in objects.lua love.test.physics.newBody = function(test) - -- setup local world = love.physics.newWorld(1, 1, true) local body = love.physics.newBody(world, 10, 10, 'static') - -- test test:assertObject(body) - -- cleanup - body:release() - world:release() end -- love.physics.newChainShape -- @NOTE this is just basic nil checking, full obj test are in objects.lua love.test.physics.newChainShape = function(test) - local obj = love.physics.newChainShape(true, 0, 0, 1, 0, 1, 1, 0, 1) - test:assertObject(obj) - obj:release() + test:assertObject(love.physics.newChainShape(true, 0, 0, 1, 0, 1, 1, 0, 1)) end -- love.physics.newCircleShape -- @NOTE this is just basic nil checking, full obj test are in objects.lua love.test.physics.newCircleShape = function(test) - local obj = love.physics.newCircleShape(10) - test:assertObject(obj) - obj:release() + test:assertObject(love.physics.newCircleShape(10)) end -- love.physics.newDistanceJoint -- @NOTE this is just basic nil checking, full obj test are in objects.lua love.test.physics.newDistanceJoint = function(test) - -- setup local world = love.physics.newWorld(1, 1, true) local body1 = love.physics.newBody(world, 10, 10, 'static') local body2 = love.physics.newBody(world, 20, 20, 'static') - -- test local obj = love.physics.newDistanceJoint(body1, body2, 10, 10, 20, 20, true) test:assertObject(obj) - -- cleanup - obj:release() - body1:release() - body2:release() - world:release() end @@ -84,25 +62,17 @@ end love.test.physics.newEdgeShape = function(test) local obj = love.physics.newEdgeShape(0, 0, 10, 10) test:assertObject(obj) - obj:release() end -- love.physics.newFixture -- @NOTE this is just basic nil checking, full obj test are in objects.lua love.test.physics.newFixture = function(test) - -- setup local world = love.physics.newWorld(1, 1, true) local body = love.physics.newBody(world, 10, 10, 'static') local shape = love.physics.newCircleShape(10) - -- test local obj = love.physics.newFixture(body, shape, 1) test:assertObject(obj) - -- cleanup - obj:release() - shape:release() - body:release() - world:release() end @@ -114,10 +84,6 @@ love.test.physics.newFrictionJoint = function(test) local body2 = love.physics.newBody(world, 20, 20, 'static') local obj = love.physics.newFrictionJoint(body1, body2, 15, 15, true) test:assertObject(obj) - obj:release() - body1:release() - body2:release() - world:release() end @@ -125,22 +91,14 @@ end -- @NOTE this is just basic nil checking, full obj test are in objects.lua love.test.physics.newGearJoint = function(test) local world = love.physics.newWorld(1, 1, true) - local body1 = love.physics.newBody(world, 10, 10, 'static') - local body2 = love.physics.newBody(world, 20, 20, 'static') - local body3 = love.physics.newBody(world, 30, 30, 'static') - local body4 = love.physics.newBody(world, 40, 40, 'static') + local body1 = love.physics.newBody(world, 10, 10, 'dynamic') + local body2 = love.physics.newBody(world, 20, 20, 'dynamic') + local body3 = love.physics.newBody(world, 30, 30, 'dynamic') + local body4 = love.physics.newBody(world, 40, 40, 'dynamic') local joint1 = love.physics.newPrismaticJoint(body1, body2, 10, 10, 20, 20, true) local joint2 = love.physics.newPrismaticJoint(body3, body4, 30, 30, 40, 40, true) local obj = love.physics.newGearJoint(joint1, joint2, 1, true) test:assertObject(obj) - obj:release() - joint1:release() - joint2:release() - body1:release() - body2:release() - body3:release() - body4:release() - world:release() end @@ -152,10 +110,6 @@ love.test.physics.newMotorJoint = function(test) local body2 = love.physics.newBody(world, 20, 20, 'static') local obj = love.physics.newMotorJoint(body1, body2, 1) test:assertObject(obj) - obj:release() - body1:release() - body2:release() - world:release() end @@ -166,9 +120,6 @@ love.test.physics.newMouseJoint = function(test) local body = love.physics.newBody(world, 10, 10, 'static') local obj = love.physics.newMouseJoint(body, 10, 10) test:assertObject(obj) - obj:release() - body:release() - world:release() end @@ -177,7 +128,6 @@ end love.test.physics.newPolygonShape = function(test) local obj = love.physics.newPolygonShape({0, 0, 2, 3, 2, 1, 3, 1, 5, 1}) test:assertObject(obj) - obj:release() end @@ -189,10 +139,6 @@ love.test.physics.newPrismaticJoint = function(test) local body2 = love.physics.newBody(world, 20, 20, 'static') local obj = love.physics.newPrismaticJoint(body1, body2, 10, 10, 20, 20, true) test:assertObject(obj) - obj:release() - body1:release() - body2:release() - world:release() end @@ -204,10 +150,6 @@ love.test.physics.newPulleyJoint = function(test) local body2 = love.physics.newBody(world, 20, 20, 'static') local obj = love.physics.newPulleyJoint(body1, body2, 10, 10, 20, 20, 15, 15, 25, 25, 1, true) test:assertObject(obj) - obj:release() - body1:release() - body2:release() - world:release() end @@ -229,10 +171,6 @@ love.test.physics.newRevoluteJoint = function(test) local body2 = love.physics.newBody(world, 20, 20, 'static') local obj = love.physics.newRevoluteJoint(body1, body2, 10, 10, true) test:assertObject(obj) - obj:release() - body1:release() - body2:release() - world:release() end @@ -244,10 +182,6 @@ love.test.physics.newRopeJoint = function(test) local body2 = love.physics.newBody(world, 20, 20, 'static') local obj = love.physics.newRopeJoint(body1, body2, 10, 10, 20, 20, 50, true) test:assertObject(obj) - obj:release() - body1:release() - body2:release() - world:release() end @@ -259,10 +193,6 @@ love.test.physics.newWeldJoint = function(test) local body2 = love.physics.newBody(world, 20, 20, 'static') local obj = love.physics.newWeldJoint(body1, body2, 10, 10, true) test:assertObject(obj) - obj:release() - body1:release() - body2:release() - world:release() end @@ -273,13 +203,7 @@ love.test.physics.newWheelJoint = function(test) local body1 = love.physics.newBody(world, 10, 10, 'static') local body2 = love.physics.newBody(world, 20, 20, 'static') local obj = love.physics.newWheelJoint(body1, body2, 10, 10, 5, 5, true) - test:assertNotEquals(nil, obj) - test:assertEquals('userdata', type(obj)) - test:assertNotEquals(nil, obj:type()) - obj:release() - body1:release() - body2:release() - world:release() + test:assertObject(obj) end @@ -288,19 +212,18 @@ end love.test.physics.newWorld = function(test) local world = love.physics.newWorld(1, 1, true) test:assertObject(world) - world:release() end -- love.physics.setMeter love.test.physics.setMeter = function(test) + -- set initial meter local world = love.physics.newWorld(1, 1, true) love.physics.setMeter(30) local body = love.physics.newBody(world, 300, 300, "dynamic") + -- check changing meter changes pos value relatively love.physics.setMeter(10) local x, y = body:getPosition() test:assertEquals(100, x, 'check pos x') test:assertEquals(100, y, 'check pos y') - body:release() - world:release() -end \ No newline at end of file +end diff --git a/testing/tests/sound.lua b/testing/tests/sound.lua index 296f6c6a0..88d3398ba 100644 --- a/testing/tests/sound.lua +++ b/testing/tests/sound.lua @@ -4,16 +4,13 @@ -- love.sound.newDecoder -- @NOTE this is just basic nil checking, full obj test are in objects.lua love.test.sound.newDecoder = function(test) - local decoder = love.sound.newDecoder('resources/click.ogg') - test:assertObject(decoder) + test:assertObject(love.sound.newDecoder('resources/click.ogg')) end -- love.sound.newSoundData -- @NOTE this is just basic nil checking, full obj test are in objects.lua love.test.sound.newSoundData = function(test) - local sounddata = love.sound.newSoundData('resources/click.ogg') - test:assertObject(sounddata) - local soundbeep = love.sound.newSoundData(math.floor((1/32)*44100), 44100, 16, 1) - test:assertObject(soundbeep) -end \ No newline at end of file + test:assertObject(love.sound.newSoundData('resources/click.ogg')) + test:assertObject(love.sound.newSoundData(math.floor((1/32)*44100), 44100, 16, 1)) +end diff --git a/testing/tests/system.lua b/testing/tests/system.lua index 9715866b5..89b8eb400 100644 --- a/testing/tests/system.lua +++ b/testing/tests/system.lua @@ -4,25 +4,31 @@ -- love.system.getClipboardText love.test.system.getClipboardText = function(test) -- ignore if not using window - if love.test.windowmode == false then return test:skipTest('clipboard only available in window mode') end - -- setup + if love.test.windowmode == false then + return test:skipTest('clipboard only available in window mode') + end + -- check clipboard value is set love.system.setClipboardText('helloworld') - -- test test:assertEquals('helloworld', love.system.getClipboardText(), 'check clipboard match') end -- love.system.getOS love.test.system.getOS = function(test) + -- check os is in documented values local os = love.system.getOS() - test:assertMatch({'OS X', 'Windows', 'Linux', 'Android', 'iOS'}, os, 'check value matches') + local options = {'OS X', 'Windows', 'Linux', 'Android', 'iOS'} + test:assertMatch(options, os, 'check value matches') end -- love.system.getPowerInfo love.test.system.getPowerInfo = function(test) + -- check battery state is one of the documented states local state, percent, seconds = love.system.getPowerInfo() - test:assertMatch({'unknown', 'battery', 'nobattery', 'charging', 'charged'}, state, 'check value matches') + local states = {'unknown', 'battery', 'nobattery', 'charging', 'charged'} + test:assertMatch(states, state, 'check value matches') + -- if percent/seconds check within expected range if percent ~= nil then test:assertRange(percent, 0, 100, 'check value within range') end @@ -34,19 +40,19 @@ end -- love.system.getProcessorCount love.test.system.getProcessorCount = function(test) - test:assertGreaterEqual(0, love.system.getProcessorCount(), 'check not nil') -- youd hope right + test:assertNotNil(love.system.getProcessorCount()) -- youd hope right end -- love.system.hasBackgroundMusic love.test.system.hasBackgroundMusic = function(test) - test:assertNotEquals(nil, love.system.hasBackgroundMusic(), 'check not nil') + test:assertNotNil(love.system.hasBackgroundMusic()) end -- love.system.openURL love.test.system.openURL = function(test) - test:skipTest('gets annoying to test everytime') + test:skipTest('cant test this worked') --test:assertNotEquals(nil, love.system.openURL('https://love2d.org'), 'check open URL') end @@ -54,8 +60,10 @@ end -- love.system.getClipboardText love.test.system.setClipboardText = function(test) -- ignore if not using window - if love.test.windowmode == false then return test:skipTest('clipboard only available in window mode') end - -- test + if love.test.windowmode == false then + return test:skipTest('clipboard only available in window mode') + end + -- check value returned is what was set love.system.setClipboardText('helloworld') test:assertEquals('helloworld', love.system.getClipboardText(), 'check set text') end @@ -64,5 +72,5 @@ end -- love.system.vibrate -- @NOTE cant really test this love.test.system.vibrate = function(test) - test:skipTest('cant really test this') -end \ No newline at end of file + test:skipTest('cant test this worked') +end diff --git a/testing/tests/thread.lua b/testing/tests/thread.lua index ed27e5b4d..8bbcab62f 100644 --- a/testing/tests/thread.lua +++ b/testing/tests/thread.lua @@ -4,25 +4,19 @@ -- love.thread.getChannel -- @NOTE this is just basic nil checking, full obj test are in objects.lua love.test.thread.getChannel = function(test) - local channel = love.thread.getChannel('test') - test:assertObject(channel) - channel:release() + test:assertObject(love.thread.getChannel('test')) end -- love.thread.newChannel -- @NOTE this is just basic nil checking, full obj test are in objects.lua love.test.thread.newChannel = function(test) - local channel = love.thread.newChannel() - test:assertObject(channel) - channel:release() + test:assertObject(love.thread.newChannel()) end -- love.thread.newThread -- @NOTE this is just basic nil checking, full obj test are in objects.lua love.test.thread.newThread = function(test) - local thread = love.thread.newThread('classes/TestSuite.lua') - test:assertObject(thread) - thread:release() -end \ No newline at end of file + test:assertObject(love.thread.newThread('classes/TestSuite.lua')) +end diff --git a/testing/tests/timer.lua b/testing/tests/timer.lua index 8228e7333..ca82449d3 100644 --- a/testing/tests/timer.lua +++ b/testing/tests/timer.lua @@ -4,20 +4,20 @@ -- love.timer.getAverageDelta -- @NOTE not sure if you could reliably get a specific delta? love.test.timer.getAverageDelta = function(test) - test:assertNotEquals(nil, love.timer.getAverageDelta(), 'check not nil') + test:assertNotNil(love.timer.getAverageDelta()) end -- love.timer.getDelta -- @NOTE not sure if you could reliably get a specific delta? love.test.timer.getDelta = function(test) - test:assertNotEquals(nil, love.timer.getDelta(), 'check not nil') + test:assertNotNil(love.timer.getDelta()) end -- love.timer.getFPS -- @NOTE not sure if you could reliably get a specific FPS? love.test.timer.getFPS = function(test) - test:assertNotEquals(nil, love.timer.getFPS(), 'check not nil') + test:assertNotNil(love.timer.getFPS()) end @@ -41,5 +41,5 @@ end -- love.timer.step -- @NOTE not sure if you could reliably get a specific step val? love.test.timer.step = function(test) - test:assertNotEquals(nil, love.timer.step(), 'check not nil') -end \ No newline at end of file + test:assertNotNil(love.timer.step()) +end diff --git a/testing/tests/video.lua b/testing/tests/video.lua index cd806c9ce..a67aaac11 100644 --- a/testing/tests/video.lua +++ b/testing/tests/video.lua @@ -4,7 +4,5 @@ -- love.video.newVideoStream -- @NOTE this is just basic nil checking, full obj test are in objects.lua love.test.video.newVideoStream = function(test) - local videostream = love.video.newVideoStream('resources/sample.ogv') - test:assertObject(videostream) - videostream:release() -end \ No newline at end of file + test:assertObject(love.video.newVideoStream('resources/sample.ogv')) +end diff --git a/testing/tests/window.lua b/testing/tests/window.lua index d89c2bfff..bb656dea8 100644 --- a/testing/tests/window.lua +++ b/testing/tests/window.lua @@ -2,19 +2,21 @@ -- love.window.close --- @NOTE closing window should cause graphics to no longer be active love.test.window.close = function(test) + -- closing window should cause graphics to not be active love.window.close() local active = false - if love.graphics ~= nil then active = love.graphics.isActive() end + if love.graphics ~= nil then + active = love.graphics.isActive() + end test:assertEquals(false, active, 'check window active') love.window.setMode(256, 256) -- reset end -- love.window.fromPixels --- @NOTE dependent on the DPI value returned I think love.test.window.fromPixels = function(test) + -- check dpi/pixel ratio as expected local dpi = love.window.getDPIScale() local pixels = love.window.fromPixels(100) test:assertEquals(100/dpi, pixels, 'check dpi ratio') @@ -22,9 +24,9 @@ end -- love.window.getDPIScale --- @NOTE i dont think there's a clever way to check this +-- @NOTE dependent on hardware so best can do is not nil love.test.window.getDPIScale = function(test) - test:assertNotEquals(nil, test, 'check not nil') + test:assertNotNil(test) end @@ -32,59 +34,58 @@ end -- @NOTE dependent on hardware so best can do is not nil love.test.window.getDesktopDimensions = function(test) local w, h = love.window.getDesktopDimensions() - test:assertNotEquals(nil, w, 'check not nil') - test:assertNotEquals(nil, h, 'check not nil') + test:assertNotNil(w) + test:assertNotNil(h) end -- love.window.getDisplayCount -- @NOTE cant wait for the test suite to be run headless and fail here love.test.window.getDisplayCount = function(test) - local count = love.window.getDisplayCount() - test:assertGreaterEqual(1, count, 'check 1 display') + test:assertGreaterEqual(1, love.window.getDisplayCount(), 'check 1 display') end -- love.window.getDisplayName -- @NOTE dependent on hardware so best can do is not nil love.test.window.getDisplayName = function(test) - local name = love.window.getDisplayName(1) - test:assertNotEquals(nil, name, 'check not nil') + test:assertNotNil(love.window.getDisplayName(1)) end -- love.window.getDisplayOrientation -- @NOTE dependent on hardware so best can do is not nil love.test.window.getDisplayOrientation = function(test) - local orientation = love.window.getDisplayOrientation(1) - test:assertNotEquals(nil, orientation, 'check not nil') + test:assertNotNil(love.window.getDisplayOrientation(1)) end -- love.window.getFullscreen love.test.window.getFullscreen = function(test) + -- check not fullscreen to start test:assertEquals(false, love.window.getFullscreen(), 'check not fullscreen') love.window.setFullscreen(true) + -- check now fullscreen test:assertEquals(true, love.window.getFullscreen(), 'check now fullscreen') - love.window.setFullscreen(false) + love.window.setFullscreen(false) -- reset end -- love.window.getFullscreenModes -- @NOTE dependent on hardware so best can do is not nil love.test.window.getFullscreenModes = function(test) - local modes = love.window.getFullscreenModes(1) - test:assertNotEquals(nil, modes, 'check not nil') + test:assertNotNil(love.window.getFullscreenModes(1)) end -- love.window.getIcon love.test.window.getIcon = function(test) - test:assertEquals(nil, love.window.getIcon(), 'check nil by default') -- nil if not set + -- check icon nil by default if not set + test:assertEquals(nil, love.window.getIcon(), 'check nil by default') local icon = love.image.newImageData('resources/love.png') + -- check getting icon not nil after setting love.window.setIcon(icon) - test:assertNotEquals(nil, love.window.getIcon(), 'check not nil') - icon:release() + test:assertNotNil(love.window.getIcon()) end @@ -112,15 +113,16 @@ end -- @NOTE dependent on hardware so best can do is not nil love.test.window.getSafeArea = function(test) local x, y, w, h = love.window.getSafeArea() - test:assertNotEquals(nil, x, 'check not nil') - test:assertNotEquals(nil, y, 'check not nil') - test:assertNotEquals(nil, w, 'check not nil') - test:assertNotEquals(nil, h, 'check not nil') + test:assertNotNil(x) + test:assertNotNil(y) + test:assertNotNil(w) + test:assertNotNil(h) end -- love.window.getTitle love.test.window.getTitle = function(test) + -- check title returned is what was set love.window.setTitle('love.testing') test:assertEquals('love.testing', love.window.getTitle(), 'check title match') love.window.setTitle('love.test') @@ -129,33 +131,37 @@ end -- love.window.getVSync love.test.window.getVSync = function(test) - test:assertNotEquals(nil, love.window.getVSync(), 'check not nil') - love.window.setVSync(false) + test:assertNotNil(love.window.getVSync()) + -- check turning off + love.window.setVSync(0) test:assertEquals(0, love.window.getVSync(), 'check vsync off') - love.window.setVSync(true) + -- check turning on + love.window.setVSync(1) test:assertEquals(1, love.window.getVSync(), 'check vsync on') end -- love.window.hasFocus --- @NOTE cant really test as cant force focus? +-- @NOTE cant really test as cant force focus love.test.window.hasFocus = function(test) - test:assertNotEquals(nil, love.window.hasFocus(), 'check not nil') + test:assertNotNil(love.window.hasFocus()) end -- love.window.hasMouseFocus --- @NOTE cant really test as cant force focus? +-- @NOTE cant really test as cant force focus love.test.window.hasMouseFocus = function(test) - test:assertNotEquals(nil, love.window.hasMouseFocus(), 'check not nil') + test:assertNotNil(love.window.hasMouseFocus()) end -- love.window.isDisplaySleepEnabled love.test.window.isDisplaySleepEnabled = function(test) - test:assertNotEquals(nil, love.window.isDisplaySleepEnabled(), 'check not nil') + test:assertNotNil(love.window.isDisplaySleepEnabled()) + -- check disabled love.window.setDisplaySleepEnabled(false) test:assertEquals(false, love.window.isDisplaySleepEnabled(), 'check sleep disabled') + -- check enabled love.window.setDisplaySleepEnabled(true) test:assertEquals(true, love.window.isDisplaySleepEnabled(), 'check sleep enabled') end @@ -163,8 +169,10 @@ end -- love.window.isMaximized love.test.window.isMaximized = function(test) + -- check minimized to start love.window.minimize() test:assertEquals(false, love.window.isMaximized(), 'check window maximized') + -- try to mazimize love.window.maximize() test:assertEquals(true, love.window.isMaximized(), 'check window not maximized') love.window.restore() @@ -173,7 +181,9 @@ end -- love.window.isMinimized love.test.window.isMinimized = function(test) + -- check not minimized to start test:assertEquals(false, love.window.isMinimized(), 'check window not minimized') + -- try to minimize love.window.minimize() test:assertEquals(true, love.window.isMinimized(), 'check window minimized') love.window.restore() @@ -182,7 +192,9 @@ end -- love.window.isOpen love.test.window.isOpen = function(test) + -- check open initially test:assertEquals(true, love.window.isOpen(), 'check window open') + -- try closing love.window.close() test:assertEquals(false, love.window.isOpen(), 'check window closed') love.window.setMode(256, 256) -- reset @@ -191,7 +203,9 @@ end -- love.window.isVisible love.test.window.isVisible = function(test) + -- check visible initially test:assertEquals(true, love.window.isVisible(), 'check window visible') + -- check closing makes window not visible love.window.close() test:assertEquals(false, love.window.isVisible(), 'check window not visible') love.window.setMode(256, 256) -- reset @@ -200,6 +214,7 @@ end -- love.window.maximize love.test.window.maximize = function(test) + -- check maximizing is set love.window.maximize() test:assertEquals(true, love.window.isMaximized(), 'check window maximized') love.window.restore() @@ -208,6 +223,7 @@ end -- love.window.minimize love.test.window.minimize = function(test) + -- check minimizing is set love.window.minimize() test:assertEquals(true, love.window.isMinimized(), 'check window minimized') love.window.restore() @@ -215,15 +231,17 @@ end -- love.window.requestAttention -love.window.requestAttention = function(test) - test:skipTest('cant really test this') +love.test.window.requestAttention = function(test) + test:skipTest('cant test this worked') end -- love.window.restore love.test.window.restore = function(test) + -- check minimized to start love.window.minimize() test:assertEquals(true, love.window.isMinimized(), 'check window minimized') + -- check restoring the state of the window love.window.restore() test:assertEquals(false, love.window.isMinimized(), 'check window restored') end @@ -231,8 +249,10 @@ end -- love.window.setDisplaySleepEnabled love.test.window.setDisplaySleepEnabled = function(test) + -- check disabling sleep love.window.setDisplaySleepEnabled(false) test:assertEquals(false, love.window.isDisplaySleepEnabled(), 'check sleep disabled') + -- check setting it back to enabled love.window.setDisplaySleepEnabled(true) test:assertEquals(true, love.window.isDisplaySleepEnabled(), 'check sleep enabled') end @@ -240,8 +260,10 @@ end -- love.window.setFullscreen love.test.window.setFullscreen = function(test) + -- check fullscreen is set love.window.setFullscreen(true) test:assertEquals(true, love.window.getFullscreen(), 'check fullscreen') + -- check setting back to normal love.window.setFullscreen(false) test:assertEquals(false, love.window.getFullscreen(), 'check not fullscreen') end @@ -250,20 +272,22 @@ end -- love.window.setIcon -- @NOTE could check the image data itself? love.test.window.setIcon = function(test) + -- check setting an icon returns the val local icon = love.image.newImageData('resources/love.png') love.window.setIcon(icon) test:assertNotEquals(nil, love.window.getIcon(), 'check icon not nil') - icon:release() end -- love.window.setMode -- @NOTE same as getMode could be checking more flag properties love.test.window.setMode = function(test) + -- set window mode love.window.setMode(512, 512, { fullscreen = false, resizable = false }) + -- 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') @@ -277,6 +301,7 @@ end -- love.window.setPosition love.test.window.setPosition = function(test) + -- check position is returned love.window.setPosition(100, 100, 1) local x, y, _ = love.window.getPosition() test:assertEquals(100, x, 'check position x') @@ -286,6 +311,7 @@ end -- love.window.setTitle love.test.window.setTitle = function(test) + -- check setting title val is returned love.window.setTitle('love.testing') test:assertEquals('love.testing', love.window.getTitle(), 'check title matches') love.window.setTitle('love.test') @@ -294,23 +320,25 @@ end -- love.window.setVSync love.test.window.setVSync = function(test) - love.window.setVSync(false) + -- check setting vsync value off + love.window.setVSync(0) test:assertEquals(0, love.window.getVSync(), 'check vsync off') - love.window.setVSync(true) + -- check setting vsync value on + love.window.setVSync(1) test:assertEquals(1, love.window.getVSync(), 'check vsync on') end -- love.window.showMessageBox -- @NOTE if running headless would need to skip anyway cos can't press it --- skipping here cos it's annoying love.test.window.showMessageBox = function(test) - test:skipTest('skipping cos annoying to test with') + test:skipTest('cant test this worked') end -- love.window.toPixels love.test.window.toPixels = function(test) + -- check dpi/pixel ratio is as expected local dpi = love.window.getDPIScale() local pixels = love.window.toPixels(50) test:assertEquals(50*dpi, pixels, 'check dpi ratio') @@ -319,18 +347,21 @@ end -- love.window.updateMode love.test.window.updateMode = function(test) + -- set initial mode love.window.setMode(512, 512, { fullscreen = false, resizable = false }) + -- update mode with some props but not others love.window.updateMode(256, 256, nil) + -- check only changed values changed local width, height, flags = love.window.getMode() test:assertEquals(256, width, 'check window w match') test:assertEquals(256, height, 'check window h match') test:assertEquals(false, flags["fullscreen"], 'check window not fullscreen') test:assertEquals(false, flags["resizable"], 'check window not resizeable') - love.window.setMode(256, 256, { + love.window.setMode(256, 256, { -- reset fullscreen = false, resizable = true }) -end \ No newline at end of file +end diff --git a/testing/todo.md b/testing/todo.md new file mode 100644 index 000000000..969cbf547 --- /dev/null +++ b/testing/todo.md @@ -0,0 +1,26 @@ +`/Applications/love_12.app/Contents/MacOS/love ./testing` + +# v0.2 + +## Changed +- Added tests for all obj creation, transformation, window + system info graphics methods +- Added half the state methods for graphics + added placeholders for missing drawing methods +- Added TestMethod:assertNotNil() for quick nil checking +- Added time total to the end of each module summary in console log to match file output + +- Removed a bunch of unessecary nil checks +- Removed :release() from test methods, collectgarbage("collect") is called between methods instead + +- Renamed /output to /examples to avoid confusion + +- Replaced love.filesystem.newFile with love.filesystem.openFile +- Replaced love.math.noise with love.math.perlinNoise / love.math.simplexNoise + +- Fixed newGearJoint throwing an error in 12 as body needs to be dynamic not static now + +- Some general cleanup, incl. better comments and time format in file output + +## Todo +- graphics state methods +- graphics drawing methods +- need a platform: format table somewhere for compressed formats (i.e. DXT not supported)