mirror of
https://github.com/gvx/bitser.git
synced 2024-11-11 01:44:21 +00:00
parent
214ad35f62
commit
5a134b4fce
@ -375,9 +375,15 @@ end, loadLoveFile = function(fname)
|
||||
-- so make sure deserialize_value returns before loadLoveFile does
|
||||
return value
|
||||
end, loadData = function(data, size)
|
||||
if size == 0 then
|
||||
error('cannot load value from empty data')
|
||||
end
|
||||
Buffer_newDataReader(data, size)
|
||||
return deserialize_value({})
|
||||
end, loads = function(str)
|
||||
if #str == 0 then
|
||||
error('cannot load value from empty string')
|
||||
end
|
||||
Buffer_newReader(str)
|
||||
return deserialize_value({})
|
||||
end, register = function(name, resource)
|
||||
|
2
conf.lua
2
conf.lua
@ -1,4 +1,4 @@
|
||||
function love.conf(t)
|
||||
t.version = "0.10.0"
|
||||
t.version = "11.3"
|
||||
t.console = true
|
||||
end
|
8
main.lua
8
main.lua
@ -48,8 +48,8 @@ local resultname = "serialisation time in seconds"
|
||||
function love.load()
|
||||
cases = love.filesystem.getDirectoryItems("cases")
|
||||
state = 'select_case'
|
||||
love.graphics.setBackgroundColor(255, 230, 220)
|
||||
love.graphics.setColor(40, 30, 0)
|
||||
love.graphics.setBackgroundColor(1, 230/256, 220/256)
|
||||
love.graphics.setColor(40/256, 30/256, 0/256)
|
||||
love.window.setTitle("Select a benchmark testcase")
|
||||
end
|
||||
|
||||
@ -168,9 +168,9 @@ function love.draw()
|
||||
for sername, result in pairs(results) do
|
||||
love.graphics.print(sername, 20, i * 20)
|
||||
if result == math.huge then
|
||||
love.graphics.setColor(220, 30, 0)
|
||||
love.graphics.setColor(220/256, 30/256, 0)
|
||||
love.graphics.rectangle('fill', 100, i * 20, 780 - 100, 18)
|
||||
love.graphics.setColor(40, 30, 0)
|
||||
love.graphics.setColor(40/256, 30/256, 0)
|
||||
else
|
||||
love.graphics.rectangle('fill', 100, i * 20, (780 - 100) * (result - results_min) / (results_max - results_min), 18)
|
||||
end
|
||||
|
@ -279,6 +279,12 @@ describe("bitser", function()
|
||||
it("can load from raw data", function()
|
||||
assert.are.same(bitser.loadData(ffi.new("uint8_t[4]", 195, 103, 118, 120), 4), "gvx")
|
||||
end)
|
||||
it("will not read from zero length data", function()
|
||||
assert.has_error(function() bitser.loadData(ffi.new("uint8_t[1]", 0), 0) end)
|
||||
end)
|
||||
it("will not read from zero length string", function()
|
||||
assert.has_error(function() bitser.loads("") end)
|
||||
end)
|
||||
it("will not read past the end of the buffer", function()
|
||||
assert.has_error(function() bitser.loadData(ffi.new("uint8_t[4]", 196, 103, 118, 120), 4) end)
|
||||
end)
|
||||
|
Loading…
Reference in New Issue
Block a user