Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions lua_cmsgpack.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
#if BITS_32
#define lua_pushunsigned(L, n) lua_pushnumber(L, n)
#else
#define lua_pushunsigned(L, n) lua_pushinteger(L, n)
#define lua_pushunsigned(L, n) ((sizeof(lua_Integer) == 4) ? lua_pushnumber(L, n) : lua_pushinteger(L, n))
#endif

/* =============================================================================
Expand Down Expand Up @@ -517,8 +517,10 @@ static int mp_pack(lua_State *L) {
int i;
mp_buf *buf;

if (nargs == 0)
return luaL_argerror(L, 0, "MessagePack pack needs input.");
if (nargs == 0){
lua_pushliteral(L, "");
return 1;
}

buf = mp_buf_new(L);
for(i = 1; i <= nargs; i++) {
Expand Down
24 changes: 18 additions & 6 deletions test.lua
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,10 @@ function test_circular(name,obj)
end
end

local function npack(...)
return select("#", ...), {...}
end

function test_stream(mod, name, ...)
io.write("Stream test '", name, "' ...\n")
if not mod then
Expand All @@ -133,27 +137,31 @@ function test_stream(mod, name, ...)
for i=1, argc do
test_circular(name, select(i, ...))
end
local ret = {mod.unpack(mod.pack(unpack({...})))}
local n, ret = npack(mod.unpack(mod.pack(unpack({...}))))
if n ~= argc then
print(" ERRORn:", "number of result not match ", n, argc)
failed = failed + 1
end
for i=1, argc do
local origin = select(i, ...)
if (type(origin) == "table") then
for k,v in pairs(origin) do
local fail = not compare_objects(v, ret[i][k])
if fail then
print("ERRORa:", k, v, " not match ", ret[i][k])
print(" ERRORa:", k, v, " not match ", ret[i][k])
failed = failed + 1
elseif not fail then
print("ok; matched stream table member")
print(" ok; matched stream table member")
passed = passed + 1
end
end
else
local fail = not compare_objects(origin, ret[i])
if fail then
print("ERRORc:", origin, " not match ", ret[i])
print(" ERRORc:", origin, " not match ", ret[i])
failed = failed + 1
elseif not fail then
print("ok; matched individual stream member")
print(" ok; matched individual stream member")
passed = passed + 1
end
end
Expand Down Expand Up @@ -326,6 +334,7 @@ end

test_global()
test_array()
test_circular("nothing");
test_circular("positive fixnum",17);
test_circular("negative fixnum",-1);
test_circular("true boolean",true);
Expand Down Expand Up @@ -418,8 +427,11 @@ test_stream(cmsgpack, "oddities", {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, {0}, {a=64}
test_stream(cmsgpack_safe, "safe oddities", {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, {0}, {a=64}, math.huge, -math.huge)
test_stream(cmsgpack, "strange things", nil, {}, {nil}, a, b, b, b, a, a, b, {c = a, d = b})
test_stream(cmsgpack_safe, "strange things", nil, {}, {nil}, a, b, b, b, a, a, b, {c = a, d = b})
test_error("pack nothing", function() cmsgpack.pack() end)
test_noerror("pack nothing", function() cmsgpack.pack() end)
test_noerror("pack nothing safe", function() cmsgpack_safe.pack() end)
test_stream(cmsgpack, "pack nothing")
test_stream(cmsgpack_safe, "pack nothing")

test_circular("large object test",
{A=9483, a=9483, aa=9483, aal=9483, aalii=9483, aam=9483, Aani=9483,
aardvark=9483, aardwolf=9483, Aaron=9483, Aaronic=9483, Aaronical=9483,
Expand Down