diff --git a/src/e9p_msg.erl b/src/e9p_msg.erl index 9e98275..4047346 100644 --- a/src/e9p_msg.erl +++ b/src/e9p_msg.erl @@ -166,7 +166,8 @@ do_parse(?Rread, <>) -> do_parse(Type, Data) -> {error, {invalid_message, Type, Data}}. -parse_stat(< [stat_encode_decode]. +all() -> [stat_encode_decode, rstat_encode_decode]. stat_encode_decode(_Conf) -> Stat = #{ @@ -27,7 +27,26 @@ stat_encode_decode(_Conf) -> gid => <<>>, muid => <<>> }, - <> = iolist_to_binary(e9p_msg:encode_stat(Stat)), + Out = iolist_to_binary(e9p_msg:encode_stat(Stat)), Decoded = e9p_msg:parse_stat(Out), ?assertEqual({ok, Stat}, Decoded). +rstat_encode_decode(_Conf) -> + Stat = #{ + type => 0, + dev => 0, + qid => e9p:make_qid(directory, 0, 0, []), + mode => 0, + atime => 0, + mtime => 0, + length => 0, + name => <<>>, + uid => <<>>, + gid => <<>>, + muid => <<>> + }, + Msg = #rstat{stat = Stat}, + Tag = 1, + Out = e9p_msg:encode(Tag, Msg), + Decoded = e9p_msg:parse(iolist_to_binary(Out)), + ?assertEqual({ok, Tag, Msg}, Decoded). diff --git a/test/prop_e9p_msg.erl b/test/prop_e9p_msg.erl index 1eabac6..00b8c8e 100644 --- a/test/prop_e9p_msg.erl +++ b/test/prop_e9p_msg.erl @@ -15,34 +15,37 @@ int(N) -> afid() -> int(2). +bin_str() -> ?LET({Charlist}, {string()}, + unicode:characters_to_binary(Charlist)). + prop_can_decode_encoded_tversion() -> - ?FORALL({Version, MPS}, {binary(), afid()}, + ?FORALL({Version, MPS}, {bin_str(), afid()}, begin enc_dec(#tversion{version = Version, max_packet_size = MPS}) end). prop_can_decode_encoded_rversion() -> - ?FORALL({Version, MPS}, {binary(), afid()}, + ?FORALL({Version, MPS}, {bin_str(), afid()}, begin enc_dec(#rversion{version = Version, max_packet_size = MPS}) end). prop_can_decode_encoded_tauth() -> - ?FORALL({Afid, Uname, Aname}, {afid(), binary(), binary()}, + ?FORALL({Afid, Uname, Aname}, {afid(), bin_str(), bin_str()}, begin enc_dec(#tauth{afid = Afid, uname = Uname, aname = Aname}) end). prop_can_decode_encoded_rerror() -> - ?FORALL({Msg}, {binary()}, + ?FORALL({Msg}, {bin_str()}, begin enc_dec(#rerror{msg = Msg}) end). prop_can_decode_encoded_rstat() -> ?FORALL({Type, Dev, Mode, Atime, Mtime, Len, Name, Uid, Gid, Muid}, - {int(2), int(2), int(4), int(4), int(4), int(8), binary(), binary(), - binary(), binary()}, + {int(2), int(2), int(4), int(4), int(4), int(8), bin_str(), bin_str(), + bin_str(), bin_str()}, begin enc_dec(#rstat{ stat = #{