diff options
author | Björn Gustavsson <[email protected]> | 2013-09-13 12:56:06 +0200 |
---|---|---|
committer | Björn Gustavsson <[email protected]> | 2013-09-18 11:45:01 +0200 |
commit | b379d700e1450a3fc7e76bb75369fa6b5eb2d327 (patch) | |
tree | 88a7ef2503b735b8cf8f51444e472facbcc2db5a /lib/asn1/test/test_partial_incomplete_decode.erl | |
parent | b8f57af261d72f9f078ddf7190201209dd846d53 (diff) | |
download | otp-b379d700e1450a3fc7e76bb75369fa6b5eb2d327.tar.gz otp-b379d700e1450a3fc7e76bb75369fa6b5eb2d327.tar.bz2 otp-b379d700e1450a3fc7e76bb75369fa6b5eb2d327.zip |
Eliminate the use of asn1_wrapper
The asn1_wrapper made some sense when encode functions
could either produce a list or a binary, depending on the
backend. Now encode functions always produce a binary.
To improve readbility of the test suites, eliminate the asn1_wrapper
functions by replacing them with calls to one of the roundtrip
functions in asn1_test_lib. When it is not possible to use
the roundtrip functions, call the module in question directly.
While at it, also remove ?line macros that are near to the
touched code and use asn1_test_lib:hex_to_bin/1 instead of
home-brewn hex conversion routines.
Diffstat (limited to 'lib/asn1/test/test_partial_incomplete_decode.erl')
-rw-r--r-- | lib/asn1/test/test_partial_incomplete_decode.erl | 116 |
1 files changed, 43 insertions, 73 deletions
diff --git a/lib/asn1/test/test_partial_incomplete_decode.erl b/lib/asn1/test/test_partial_incomplete_decode.erl index 8ede06938d..4a8a4cd74c 100644 --- a/lib/asn1/test/test_partial_incomplete_decode.erl +++ b/lib/asn1/test/test_partial_incomplete_decode.erl @@ -25,84 +25,57 @@ test(Config) -> FMsg = msg('F'), - ?line {ok,Bytes} = asn1_wrapper:encode('PartialDecSeq','F',FMsg), - ?line {ok,_} = asn1_wrapper:decode('PartialDecSeq','F',Bytes), - ?line {ok,IncFMsg} = - 'PartialDecSeq':decode_F_fb_incomplete(list_to_binary(Bytes)), - ?line decode_parts('F',IncFMsg), + Bytes1 = roundtrip('PartialDecSeq', 'F', FMsg), + {ok,IncFMsg} = 'PartialDecSeq':decode_F_fb_incomplete(Bytes1), + decode_parts('F', IncFMsg), + {ok,IncF2Msg} = 'PartialDecSeq':decode_F_fb_exclusive2(Bytes1), + decode_parts('F2', IncF2Msg), DMsg = msg('D'), - ?line {ok,Bytes2} = asn1_wrapper:encode('PartialDecSeq','D',DMsg), - ?line {ok,_} = asn1_wrapper:decode('PartialDecSeq','D',Bytes2), - ?line {ok,IncDMsg} = - 'PartialDecSeq':decode_D_incomplete(list_to_binary(Bytes2)), - ?line decode_parts('D',IncDMsg), - - ?line {ok,IncF2Msg} = - 'PartialDecSeq':decode_F_fb_exclusive2(list_to_binary(Bytes)), - ?line decode_parts('F2',IncF2Msg), + Bytes2 = roundtrip('PartialDecSeq', 'D', DMsg), + {ok,IncDMsg} = 'PartialDecSeq':decode_D_incomplete(Bytes2), + decode_parts('D', IncDMsg), F3Msg = msg('F3'), - ?line {ok,BytesF3} = asn1_wrapper:encode('PartialDecSeq','F',F3Msg), - ?line {ok,_} = asn1_wrapper:decode('PartialDecSeq','F',BytesF3), - ?line {ok,IncF3Msg} = - 'PartialDecSeq':decode_F_fb_exclusive3(list_to_binary(BytesF3)), - ?line decode_parts('F3',IncF3Msg), - - - AMsg =msg('A'), - ?line {ok,Bytes3} = asn1_wrapper:encode('PartialDecSeq2','A',AMsg), - ?line {ok,_} = asn1_wrapper:decode('PartialDecSeq2','A',Bytes3), - ?line {ok,IncFMsg3} = - 'PartialDecSeq2':decode_A_c_b_incomplete(list_to_binary(Bytes3)), - ?line decode_parts('A',IncFMsg3), + BytesF3 = roundtrip('PartialDecSeq', 'F', F3Msg), + {ok,IncF3Msg} = 'PartialDecSeq':decode_F_fb_exclusive3(BytesF3), + decode_parts('F3', IncF3Msg), + + AMsg = msg('A'), + Bytes3 = roundtrip('PartialDecSeq2', 'A', AMsg), + {ok,IncFMsg3} = 'PartialDecSeq2':decode_A_c_b_incomplete(Bytes3), + decode_parts('A', IncFMsg3), MyHTTPMsg = msg('GetRequest'), - ?line {ok,Bytes4} = asn1_wrapper:encode('PartialDecMyHTTP', - 'GetRequest',MyHTTPMsg), - ?line {ok,_} = asn1_wrapper:decode('PartialDecMyHTTP','GetRequest', - Bytes4), - ?line {ok,IncFMsg4} = - 'PartialDecMyHTTP':decode_GetRequest_incomplete(list_to_binary(Bytes4)), - ?line decode_parts('GetRequest',IncFMsg4), + Bytes4 = roundtrip('PartialDecMyHTTP', 'GetRequest', MyHTTPMsg), + {ok,IncFMsg4} = 'PartialDecMyHTTP':decode_GetRequest_incomplete(Bytes4), + decode_parts('GetRequest', IncFMsg4), MsgS1_1 = msg('S1_1'), - ?line {ok,Bytes5} = asn1_wrapper:encode('PartialDecSeq3','S1',MsgS1_1), - ?line {ok,_} = asn1_wrapper:decode('PartialDecSeq3','S1',Bytes5), - ?line {ok,IncFMsg5} = - 'PartialDecSeq3':decode_S1_incomplete(list_to_binary(Bytes5)), - ?line decode_parts('S1_1',IncFMsg5), + Bytes5 = roundtrip('PartialDecSeq3', 'S1', MsgS1_1), + {ok,IncFMsg5} = 'PartialDecSeq3':decode_S1_incomplete(Bytes5), + decode_parts('S1_1', IncFMsg5), MsgS1_2 = msg('S1_2'), - ?line {ok,Bytes6} = asn1_wrapper:encode('PartialDecSeq3','S1',MsgS1_2), - ?line {ok,IncFMsg6} = - 'PartialDecSeq3':decode_S1_incomplete(list_to_binary(Bytes6)), - ?line ok = decode_parts('S1_2',IncFMsg6), + Bytes6 = roundtrip('PartialDecSeq3', 'S1', MsgS1_2), + {ok,IncFMsg6} = 'PartialDecSeq3':decode_S1_incomplete(Bytes6), + decode_parts('S1_2', IncFMsg6), %% test of MEDIA-GATEWAY-CONTROL test_megaco(Config), ok. test_megaco(Config) -> - ?line DataDir = ?config(data_dir,Config), - Mod='MEDIA-GATEWAY-CONTROL', - ?line {ok,FilenameList} = file:list_dir(filename:join([DataDir, - megacomessages])), - %% remove any junk files that may be in the megacomessage directory - Pred = fun(X) -> - case lists:reverse(X) of - [$l,$a,$v,$.|_R] ->true; - _ -> false - end - end, - MegacoMsgFilenameList = lists:filter(Pred,FilenameList), - Fun = fun(F) -> - M = read_msg(filename:join([DataDir,megacomessages,F])), - ?line {ok,B} = asn1_wrapper:encode(Mod,element(1,M),M), - ?line exclusive_decode(list_to_binary(B),F) - end, - ?line lists:foreach(Fun,MegacoMsgFilenameList), - ok. + DataDir = ?config(data_dir, Config), + Files = filelib:wildcard(filename:join([DataDir,megacomessages,"*.val"])), + Mod = 'MEDIA-GATEWAY-CONTROL', + lists:foreach(fun(File) -> + {ok,Bin} = file:read_file(File), + V = binary_to_term(Bin), + T = element(1, V), + Enc = roundtrip(Mod, T, V), + exclusive_decode(Enc, File) + end, Files). exclusive_decode(Bin,F) -> Mod='MEDIA-GATEWAY-CONTROL', @@ -113,15 +86,6 @@ exclusive_decode(Bin,F) -> ?line {ok,_} = Mod:decode_part(MsgMBodyKey,MsgMBody), ok. - -read_msg(File) -> - case file:read_file(File) of - {ok,Bin} -> - binary_to_term(Bin); - _ -> - io:format("couldn't read file ~p~n",[File]) - end. - decode_parts('F',PartDecMsg) -> ?line {fb,{'E',35,{NameE_b,ListBinE_b},false,{NameE_d,BinE_d}}} = PartDecMsg, ?line {ok,[{'D',3,true}|_]} = 'PartialDecSeq':decode_part(NameE_b,ListBinE_b), @@ -200,7 +164,10 @@ msg('A') -> {'A',12,{c,{'S',true,false}},{b,{'A_c_b',false,false}}}; msg('GetRequest') -> - {'GetRequest',true,false,{'AcceptTypes',[1,1,1,1],["hell","othe","reho","peyo","uare","fine"]},"IamfineThankYOu"}; + {'GetRequest',true,false, + {'AcceptTypes',[html,'plain-text',gif,jpeg], + ["hell","othe","reho","peyo","uare","fine"]}, + "IamfineThankYOu"}; msg('S1_1') -> {'S1',14,msg('S2'),msg('C1_a'),msg('SO1')}; @@ -213,10 +180,13 @@ msg('C1_a') -> msg('C1_b') -> {b,{'C1_b',11,true,msg('S4')}}; msg('S3') -> - {'S3',10,"PrintableString","OCTETSTRING",[1,1,1,1]}; + {'S3',10,"PrintableString","OCTETSTRING",[one,two,three,four]}; msg('S4') -> {'S4',msg('Name'),"MSc"}; msg('SO1') -> [msg('Name'),msg('Name'),msg('Name')]; msg('Name') -> {'Name',"Hans","HCA","Andersen"}. + +roundtrip(M, T, V) -> + asn1_test_lib:roundtrip_enc(M, T, V). |