diff options
author | Björn Gustavsson <[email protected]> | 2013-09-11 10:48:49 +0200 |
---|---|---|
committer | Björn Gustavsson <[email protected]> | 2013-09-18 11:45:00 +0200 |
commit | 233089914b1d70c0b0ddc46b1977998aa4bd3780 (patch) | |
tree | 497aab1c757bf252f0a0b1d0fbde449ccaa0b0fc /lib/asn1/test/asn1_test_lib.erl | |
parent | 973fae5673fee766fd5477fbf3663b2722cab9d7 (diff) | |
download | otp-233089914b1d70c0b0ddc46b1977998aa4bd3780.tar.gz otp-233089914b1d70c0b0ddc46b1977998aa4bd3780.tar.bz2 otp-233089914b1d70c0b0ddc46b1977998aa4bd3780.zip |
asn1_test_lib: Add roundtrip functions and use them everywhere
Even if the roundtrip functions are very simply, putting them here
makes it possible to change its behavior in one place (e.g. if we
are to change encode and decode not to wrap the result in a ok tuple
in some future release).
Diffstat (limited to 'lib/asn1/test/asn1_test_lib.erl')
-rw-r--r-- | lib/asn1/test/asn1_test_lib.erl | 23 |
1 files changed, 19 insertions, 4 deletions
diff --git a/lib/asn1/test/asn1_test_lib.erl b/lib/asn1/test/asn1_test_lib.erl index 530d2a38a1..417380159e 100644 --- a/lib/asn1/test/asn1_test_lib.erl +++ b/lib/asn1/test/asn1_test_lib.erl @@ -19,10 +19,9 @@ %% -module(asn1_test_lib). --export([compile/3]). --export([compile_all/3]). --export([compile_erlang/3]). --export([hex_to_bin/1]). +-export([compile/3,compile_all/3,compile_erlang/3, + hex_to_bin/1, + roundtrip/3,roundtrip/4,roundtrip_enc/3,roundtrip_enc/4]). -include_lib("test_server/include/test_server.hrl"). @@ -54,6 +53,22 @@ compile_erlang(Mod, Config, Options) -> hex_to_bin(S) -> << <<(hex2num(C)):4>> || C <- S, C =/= $\s >>. +roundtrip(Mod, Type, Value) -> + roundtrip(Mod, Type, Value, Value). + +roundtrip(Mod, Type, Value, ExpectedValue) -> + {ok,Encoded} = Mod:encode(Type, Value), + {ok,ExpectedValue} = Mod:decode(Type, Encoded), + ok. + +roundtrip_enc(Mod, Type, Value) -> + roundtrip_enc(Mod, Type, Value, Value). + +roundtrip_enc(Mod, Type, Value, ExpectedValue) -> + {ok,Encoded} = Mod:encode(Type, Value), + {ok,ExpectedValue} = Mod:decode(Type, Encoded), + Encoded. + %%% %%% Internal functions. %%% |