Files
love/testing/tests/sound.lua
T
ell 990259edf9 more tests
- added custom error handler so that love is closed if a crash occurs rather than hang on the graphic screen (for runner crashes mainly)

- updated missing functions left todo in todo.md and removed list from readme.md to make it easier to keep track of

- added love.audio.getPlaybackDevice(), love.audio.getPlaybackDevices(), love.audio.setPlaybackDevice()

- added love.data.ByteData:setString()

- added love.filesystem.getFullCommonPath(), love.filesystem.mountFullPath(), love.filesystem.unmountFullPath(), love.filesystem.moundCommonPath(), plus optional b/t/bt params to love.filesystem.load()

- added love.keyboard.isModifierActive()

- added love.sound.SoundData:copy() and love.sound.SoundData:slice()

- added love.graphics.Texture:isCanvas() and love.graphics.Texture:isComputeWritable()

- added love.image.ImageData:isLinear(), love.image.ImageData:setLinear(), and love.image.ImageData:encode("*.exr")

- added love.image.CompressedImageData:isLinear() and love.image.CompressedImageData:setLinear()

- added love.system.getPreferredLocales()

- added love.window.focus() and removed love.window.close() (now deprecated)
2024-02-28 17:49:51 +00:00

119 lines
4.4 KiB
Lua

-- love.sound
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
------------------------------------OBJECTS-------------------------------------
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
-- Decoder (love.sound.newDecoder)
love.test.sound.Decoder = function(test)
-- create obj
local decoder = love.sound.newDecoder('resources/click.ogg')
test:assertObject(decoder)
-- check bit depth
test:assertMatch({8, 16}, decoder:getBitDepth(), 'check bit depth')
-- check channel count
test:assertMatch({1, 2}, decoder:getChannelCount(), 'check channel count')
-- check duration
test:assertRange(decoder:getDuration(), 0.06, 0.07, 'check duration')
-- check sample rate
test:assertEquals(44100, decoder:getSampleRate(), 'check sample rate')
-- check makes sound data (test in method below)
test:assertObject(decoder:decode())
-- check cloning sound
local clone = decoder:clone()
test:assertMatch({8, 16}, clone:getBitDepth(), 'check cloned bit depth')
test:assertMatch({1, 2}, clone:getChannelCount(), 'check cloned channel count')
test:assertRange(clone:getDuration(), 0.06, 0.07, 'check cloned duration')
test:assertEquals(44100, clone:getSampleRate(), 'check cloned sample rate')
end
-- SoundData (love.sound.newSoundData)
love.test.sound.SoundData = function(test)
-- create obj
local sdata = love.sound.newSoundData('resources/click.ogg')
test:assertObject(sdata)
-- check data size + string
test:assertEquals(11708, sdata:getSize(), 'check size')
test:assertNotNil(sdata:getString())
-- check bit depth
test:assertMatch({8, 16}, sdata:getBitDepth(), 'check bit depth')
-- check channel count
test:assertMatch({1, 2}, sdata:getChannelCount(), 'check channel count')
-- check duration
test:assertRange(sdata:getDuration(), 0.06, 0.07, 'check duration')
-- check samples
test:assertEquals(44100, sdata:getSampleRate(), 'check sample rate')
test:assertEquals(2927, sdata:getSampleCount(), 'check sample count')
-- check cloning
local clone = sdata:clone()
test:assertEquals(11708, clone:getSize(), 'check clone size')
test:assertNotNil(clone:getString())
test:assertMatch({8, 16}, clone:getBitDepth(), 'check clone bit depth')
test:assertMatch({1, 2}, clone:getChannelCount(), 'check clone channel count')
test:assertRange(clone:getDuration(), 0.06, 0.07, 'check clone duration')
test:assertEquals(44100, clone:getSampleRate(), 'check clone sample rate')
test:assertEquals(2927, clone:getSampleCount(), 'check clone sample count')
-- check sample setting
test:assertRange(sdata:getSample(0.001), -0.1, 0, 'check sample 1')
test:assertRange(sdata:getSample(0.005), -0.1, 0, 'check sample 1')
sdata:setSample(0.002, 1)
test:assertEquals(1, sdata:getSample(0.002), 'check setting sample manually')
-- check copying from another sound
local copy1 = love.sound.newSoundData('resources/tone.ogg')
local copy2 = love.sound.newSoundData('resources/pop.ogg')
local before = copy2:getSample(0.02)
copy2:copyFrom(copy1, 0.01, 1, 0.02)
test:assertNotEquals(before, copy2:getSample(0.02), 'check changed')
-- check slicing
local count = math.floor(copy1:getSampleCount()/2)
local slice = copy1:slice(0, count)
test:assertEquals(count, slice:getSampleCount(), 'check slice length')
end
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
------------------------------------METHODS-------------------------------------
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
-- love.sound.newDecoder
-- @NOTE this is just basic nil checking, objs have their own test method
love.test.sound.newDecoder = function(test)
test:assertObject(love.sound.newDecoder('resources/click.ogg'))
end
-- love.sound.newSoundData
-- @NOTE this is just basic nil checking, objs have their own test method
love.test.sound.newSoundData = function(test)
test:assertObject(love.sound.newSoundData('resources/click.ogg'))
test:assertObject(love.sound.newSoundData(math.floor((1/32)*44100), 44100, 16, 1))
end