Files
love/testing/tests/image.lua
T
ell 09d0ace4b6 finished a bunch of modules
- finished audio module
- finished data module
- finished filesystem module
- finished font module (note: glphy test fails, but seems to be a 12.0 issue)
- finished image module
- finished maths module
- finished sound module
- finished thread module
- finished video module
- fixed pcall error not showing in results for invalid test code
2023-10-14 18:18:53 +01:00

102 lines
4.1 KiB
Lua

-- love.image
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
------------------------------------OBJECTS-------------------------------------
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
-- CompressedImageData (love.image.newCompressedImageData)
love.test.image.CompressedImageData = function(test)
-- create obj
local idata = love.image.newCompressedData('resources/love.dxt1')
test:assertObject(idata)
-- check data properties
test:assertNotEquals(nil, idata:getString(), 'check data string')
test:assertEquals(2744, idata:getSize(), 'check data size')
-- check img data properties
local iw, ih = idata:getDimensions()
test:assertEquals(64, iw, 'check image dimension w')
test:assertEquals(64, ih, 'check image dimension h')
test:assertEquals('DXT1', idata:getFormat(), 'check image format')
test:assertEquals(64, idata:getWidth(), 'check image direct w')
test:assertEquals(64, idata:getHeight(), 'check image direct h')
test:assertEquals(7, idata:getMipmapCount(), 'check mipmap count')
end
-- ImageData (love.image.newImageData)
love.test.image.ImageData = function(test)
-- create obj
local idata = love.image.newImageData('resources/love.png')
test:assertObject(idata)
-- check data properties
test:assertNotEquals(nil, idata:getString(), 'check data string')
test:assertEquals(16384, idata:getSize(), 'check data size')
-- check img data properties
local iw, ih = idata:getDimensions()
test:assertEquals(64, iw, 'check image dimension w')
test:assertEquals(64, ih, 'check image dimension h')
test:assertEquals('rgba8', idata:getFormat(), 'check image format')
test:assertEquals(64, idata:getWidth(), 'check image direct w')
test:assertEquals(64, idata:getHeight(), 'check image direct h')
-- manipulate image data so white heart is black
local mapdata = function(x, y, r, g, b, a)
if r == 1 and g == 1 and b == 1 then
r = 0; g = 0; b = 0
end
return r, g, b, a
end
idata:mapPixel(mapdata, 0, 0, 64, 64)
local r1, g1, b1 = idata:getPixel(25, 25)
test:assertEquals(0, r1+g1+b1, 'check mapped black')
-- map some other data into the idata
local idata2 = love.image.newImageData('resources/loveinv.png')
idata:paste(idata2, 0, 0, 0, 0)
r1, g1, b1 = idata:getPixel(25, 25)
test:assertEquals(3, r1+g1+b1, 'check back to white')
-- set pixels directly
idata:setPixel(25, 25, 1, 0, 0, 1)
r1, g1, b1 = idata:getPixel(25, 25)
test:assertEquals(1, r1+g1+b1, 'check set to red')
-- check encoding to an image
idata:encode('png', 'test-encode.png')
local read = love.filesystem.openFile('test-encode.png', 'r')
test:assertNotNil(read)
love.filesystem.remove('test-encode.png')
end
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
------------------------------------METHODS-------------------------------------
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
-- 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)
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, objs have their own test method
love.test.image.newCompressedData = function(test)
test:assertObject(love.image.newCompressedData('resources/love.dxt1'))
end
-- love.image.newImageData
-- @NOTE this is just basic nil checking, objs have their own test method
love.test.image.newImageData = function(test)
test:assertObject(love.image.newImageData('resources/love.png'))
test:assertObject(love.image.newImageData(16, 16, 'rgba8', nil))
end