add some eunit tests

This commit is contained in:
UENISHI Kota 2014-01-18 16:38:59 +09:00
parent 2ed212627f
commit 5d297d818c
2 changed files with 10 additions and 4 deletions

View File

@ -0,0 +1,3 @@
#ifndef MSGPACK_NIF_H
#define MSGPACK_NIF_H
#endif

View File

@ -29,6 +29,7 @@ init()->
end,
erlang:load_nif(SoName, 0).
%% @doc 'pack' in old spec using nif.
-spec pack(msgpack:object()) -> binary() | {error, {badarg, term()}}.
pack(_) ->
throw(nif_not_loaded).
@ -37,8 +38,6 @@ pack(_) ->
unpack_stream(_) ->
throw(nif_not_loaded).
%% NOTE: nif is disabled until new C version is released.
-undef(TEST).
-ifdef(TEST).
mini_test()->
@ -52,8 +51,7 @@ mini_test()->
?assertEqual({{[{23,23}]}, <<>>},
msgpack_nif:unpack_stream(msgpack:pack({[{23,23}]}))),
?assertEqual({ok, {[]}}, msgpack_nif:unpack(msgpack_nif:pack({[]}))),
%% ?assertEqual({ok, {[]}}, msgpack_nif:unpack(msgpack_nif:pack({[]}))),
?assertEqual({ok, 2345}, msgpack:unpack(msgpack_nif:pack(2345))),
?assertEqual({ok, [2345]}, msgpack:unpack(msgpack_nif:pack([2345]))),
@ -61,4 +59,9 @@ mini_test()->
msgpack:unpack(msgpack_nif:pack({[{34,45}]}))),
ok.
fail_test() ->
?assertException(error, nif_with_ext,
msgpack:pack([], [{use_nif,true},{ext, msgpack_term}])).
%% ok.
-endif.