From c732feb551691b56c2edf7c4308cd36aa3e75bfa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Gustavsson?= Date: Wed, 12 Dec 2012 16:01:23 +0100 Subject: Simplify testChoExtension by introducing a roundtrip/2 function --- lib/asn1/test/testChoExtension.erl | 41 ++++++++++++-------------------------- 1 file changed, 13 insertions(+), 28 deletions(-) (limited to 'lib/asn1/test') diff --git a/lib/asn1/test/testChoExtension.erl b/lib/asn1/test/testChoExtension.erl index b75cfb6831..067d4d2bf7 100644 --- a/lib/asn1/test/testChoExtension.erl +++ b/lib/asn1/test/testChoExtension.erl @@ -25,42 +25,27 @@ extension(_Rules) -> - - ?line {ok,Bytes1} = asn1_wrapper:encode('ChoExtension','ChoExt1',{'ChoExt1',{bool,true}}), - ?line {ok,{bool,true}} = - asn1_wrapper:decode('ChoExtension','ChoExt1',lists:flatten(Bytes1)), - - ?line {ok,Bytes2} = asn1_wrapper:encode('ChoExtension','ChoExt1',{'ChoExt1',{int,33}}), - ?line {ok,{int,33}} = - asn1_wrapper:decode('ChoExtension','ChoExt1',lists:flatten(Bytes2)), + roundtrip('ChoExt1', {bool,true}), + roundtrip('ChoExt1', {int,33}), %% A trick to encode with another compatible CHOICE type to test reception %% extension alternative - ?line {ok,Bytes2x} = asn1_wrapper:encode('ChoExtension','ChoExt1x',{str,"abc"}), - ?line {ok,Val2x} = + {ok,Bytes2x} = asn1_wrapper:encode('ChoExtension','ChoExt1x',{str,"abc"}), + {ok,Val2x} = asn1_wrapper:decode('ChoExtension','ChoExt1',lists:flatten(Bytes2x)), io:format("Choice extension alternative = ~p~n",[Val2x]), - ?line {ok,Bytes3} = asn1_wrapper:encode('ChoExtension','ChoExt2',{'ChoExt2',{bool,true}}), - ?line {ok,{bool,true}} = - asn1_wrapper:decode('ChoExtension','ChoExt2',lists:flatten(Bytes3)), - - ?line {ok,Bytes4} = asn1_wrapper:encode('ChoExtension','ChoExt2',{'ChoExt2',{int,33}}), - ?line {ok,{int,33}} = - asn1_wrapper:decode('ChoExtension','ChoExt2',lists:flatten(Bytes4)), + roundtrip('ChoExt2', {bool,true}), + roundtrip('ChoExt2', {int,33}), + roundtrip('ChoExt3', {bool,true}), + roundtrip('ChoExt3', {int,33}), + roundtrip('ChoExt4', {str,"abc"}), - ?line {ok,Bytes5} = asn1_wrapper:encode('ChoExtension','ChoExt3',{'ChoExt3',{bool,true}}), - ?line {ok,{bool,true}} = - asn1_wrapper:decode('ChoExtension','ChoExt3',lists:flatten(Bytes5)), - - ?line {ok,Bytes6} = asn1_wrapper:encode('ChoExtension','ChoExt3',{'ChoExt3',{int,33}}), - ?line {ok,{int,33}} = - asn1_wrapper:decode('ChoExtension','ChoExt3',lists:flatten(Bytes6)), - - Val7 = {str,"abc"}, - ?line {ok,Bytes7} = asn1_wrapper:encode('ChoExtension','ChoExt4',Val7), - ?line {ok,Val7} = asn1_wrapper:decode('ChoExtension','ChoExt4',lists:flatten(Bytes7)), + ok. +roundtrip(Type, Value) -> + {ok,Encoded} = 'ChoExtension':encode(Type, Value), + {ok,Value} = 'ChoExtension':decode(Type, Encoded), ok. -- cgit v1.2.3