diff options
author | Björn Gustavsson <bjorn@erlang.org> | 2013-09-13 12:56:06 +0200 |
---|---|---|
committer | Björn Gustavsson <bjorn@erlang.org> | 2013-09-18 11:45:01 +0200 |
commit | b379d700e1450a3fc7e76bb75369fa6b5eb2d327 (patch) | |
tree | 88a7ef2503b735b8cf8f51444e472facbcc2db5a /lib/asn1/test/testMegaco.erl | |
parent | b8f57af261d72f9f078ddf7190201209dd846d53 (diff) | |
download | erlang-b379d700e1450a3fc7e76bb75369fa6b5eb2d327.tar.gz |
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/testMegaco.erl')
-rw-r--r-- | lib/asn1/test/testMegaco.erl | 51 |
1 files changed, 11 insertions, 40 deletions
diff --git a/lib/asn1/test/testMegaco.erl b/lib/asn1/test/testMegaco.erl index f954f506b6..644042b484 100644 --- a/lib/asn1/test/testMegaco.erl +++ b/lib/asn1/test/testMegaco.erl @@ -24,53 +24,24 @@ -include_lib("test_server/include/test_server.hrl"). -compile(_Config,ber,[optimize]) -> - {ok,no_module,no_module}; -compile(_Config,per,[optimize]) -> - {ok,no_module,no_module}; -compile(Config,Erule,Options) -> +compile(Config, Erule, Options) -> asn1_test_lib:compile("MEDIA-GATEWAY-CONTROL.asn", Config, [Erule|Options]), asn1_test_lib:compile("OLD-MEDIA-GATEWAY-CONTROL.asn", Config, [Erule|Options]), {ok,'OLD-MEDIA-GATEWAY-CONTROL','MEDIA-GATEWAY-CONTROL'}. - main(no_module,_) -> ok; main('OLD-MEDIA-GATEWAY-CONTROL',Config) -> CaseDir = ?config(case_dir, Config), {ok,Msg} = asn1ct:value('OLD-MEDIA-GATEWAY-CONTROL','MegacoMessage', [{i, CaseDir}]), - ?line {ok,Bytes} = asn1_wrapper:encode('OLD-MEDIA-GATEWAY-CONTROL', - 'MegacoMessage',Msg), - ?line {ok,Msg} = asn1_wrapper:decode('OLD-MEDIA-GATEWAY-CONTROL', - 'MegacoMessage', - Bytes), + asn1_test_lib:roundtrip('OLD-MEDIA-GATEWAY-CONTROL', 'MegacoMessage', Msg), ok; -main(Mod='MEDIA-GATEWAY-CONTROL',Config) -> - ?line DataDir = ?config(data_dir,Config), - io:format("DataDir:~p~n",[DataDir]), - ?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])), - {ok,B} = asn1_wrapper:encode(Mod,element(1,M),M), - {ok,M} = asn1_wrapper:decode(Mod,element(1,M),B) - end, - ?line lists:foreach(Fun,MegacoMsgFilenameList), - 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. +main('MEDIA-GATEWAY-CONTROL'=Mod, Config) -> + DataDir = ?config(data_dir, Config), + Files = filelib:wildcard(filename:join([DataDir,megacomessages,"*.val"])), + lists:foreach(fun(File) -> + {ok,Bin} = file:read_file(File), + V = binary_to_term(Bin), + T = element(1, V), + asn1_test_lib:roundtrip(Mod, T, V) + end, Files). |