mirror of
https://github.com/love2d/love.git
synced 2026-08-12 16:40:57 +02:00
f846d4ab91
- spaced out object class tests and added more defined comment groups - changed reusing vars in case it causes unexpected asserts in future - fixed some shape:point test having wrong params - added assertTrue + assertFalse for basic checks - used assertRange more for some of the physics + audio tests
107 lines
3.9 KiB
Lua
107 lines
3.9 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')
|
|
|
|
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
|