aboutsummaryrefslogtreecommitdiffstats
path: root/lib/asn1/test/testSeqOf.erl
diff options
context:
space:
mode:
Diffstat (limited to 'lib/asn1/test/testSeqOf.erl')
-rw-r--r--lib/asn1/test/testSeqOf.erl258
1 files changed, 76 insertions, 182 deletions
diff --git a/lib/asn1/test/testSeqOf.erl b/lib/asn1/test/testSeqOf.erl
index 1aa1eab26d..771045f9af 100644
--- a/lib/asn1/test/testSeqOf.erl
+++ b/lib/asn1/test/testSeqOf.erl
@@ -28,193 +28,87 @@
-record('Seq3',{bool3, seq3 = asn1_DEFAULT, int3}).
-record('Seq4',{seq41 = asn1_DEFAULT, seq42 = asn1_DEFAULT, seq43 = asn1_DEFAULT}).
-record('SeqIn',{boolIn, intIn}).
-%-record('SeqCho',{bool1, int1, seq1 = asn1_DEFAULT}).
-%-record('SeqChoInline',{bool1, int1, seq1 = asn1_DEFAULT}).
-%-record('SeqChoOfInline_SEQOF',{bool1, int1, seq1 = asn1_DEFAULT}).
-record('SeqEmp',{seq1}).
-record('Empty',{}).
-main(Rules) ->
-
- ?line {ok,Bytes11} =
- asn1_wrapper:encode('SeqOf','Seq1',#'Seq1'{bool1 = true,
- int1 = 17}),
- ?line {ok,{'Seq1',true,17,[]}} =
- asn1_wrapper:decode('SeqOf','Seq1',lists:flatten(Bytes11)),
-
-
- ?line {ok,Bytes12} =
- asn1_wrapper:encode('SeqOf','Seq1',#'Seq1'{bool1 = true,
- int1 = 17,
- seq1 = [#'SeqIn'{boolIn = true,
- intIn = 25}]}),
- ?line {ok,{'Seq1',true,17,[{'SeqIn',true,25}]}} =
- asn1_wrapper:decode('SeqOf','Seq1',lists:flatten(Bytes12)),
-
-
-
- ?line {ok,Bytes13} =
- asn1_wrapper:encode('SeqOf','Seq1',#'Seq1'{bool1 = true,
- int1 = 17,
- seq1 = [#'SeqIn'{boolIn = true,
- intIn = 25},
- #'SeqIn'{boolIn = false,
- intIn = 125},
- #'SeqIn'{boolIn = false,
- intIn = 225}]}),
- ?line {ok,{'Seq1',true,17,[{'SeqIn',true,25},{'SeqIn',false,125},{'SeqIn',false,225}]}} =
- asn1_wrapper:decode('SeqOf','Seq1',lists:flatten(Bytes13)),
-
-
-
-
-
-
- ?line {ok,Bytes21} =
- asn1_wrapper:encode('SeqOf','Seq2',#'Seq2'{bool2 = true,
- int2 = 17}),
-
- ?line {ok,{'Seq2',[],true,17}} =
- asn1_wrapper:decode('SeqOf','Seq2',lists:flatten(Bytes21)),
-
-
- ?line {ok,Bytes22} =
- asn1_wrapper:encode('SeqOf','Seq2',#'Seq2'{bool2 = true,
- int2 = 17,
- seq2 = [#'SeqIn'{boolIn = true,
- intIn = 25}]}),
- ?line {ok,{'Seq2',[{'SeqIn',true,25}],true,17}} =
- asn1_wrapper:decode('SeqOf','Seq2',lists:flatten(Bytes22)),
-
-
- ?line {ok,Bytes23} =
- asn1_wrapper:encode('SeqOf','Seq2',#'Seq2'{bool2 = true,
- int2 = 17,
- seq2 = [#'SeqIn'{boolIn = true,
- intIn = 25},
- #'SeqIn'{boolIn = false,
- intIn = 125},
- #'SeqIn'{boolIn = false,
- intIn = 225}]}),
- ?line {ok,{'Seq2',[{'SeqIn',true,25},{'SeqIn',false,125},{'SeqIn',false,225}],true,17}} =
- asn1_wrapper:decode('SeqOf','Seq2',lists:flatten(Bytes23)),
-
-
-
-
-
-
- ?line {ok,Bytes31} =
- asn1_wrapper:encode('SeqOf','Seq3',#'Seq3'{bool3 = true,
- int3 = 17}),
- ?line {ok,{'Seq3',true,[],17}} =
- asn1_wrapper:decode('SeqOf','Seq3',lists:flatten(Bytes31)),
-
-
- ?line {ok,Bytes32} =
- asn1_wrapper:encode('SeqOf','Seq3',#'Seq3'{bool3 = true,
- int3 = 17,
- seq3 = [#'SeqIn'{boolIn = true,
- intIn = 25}]}),
- ?line {ok,{'Seq3',true,[{'SeqIn',true,25}],17}} =
- asn1_wrapper:decode('SeqOf','Seq3',lists:flatten(Bytes32)),
-
-
- ?line {ok,Bytes33} =
- asn1_wrapper:encode('SeqOf','Seq3',#'Seq3'{bool3 = true,
- int3 = 17,
- seq3 = [#'SeqIn'{boolIn = true,
- intIn = 25},
- #'SeqIn'{boolIn = false,
- intIn = 125},
- #'SeqIn'{boolIn = false,
- intIn = 225}]}),
- ?line {ok,{'Seq3',true,[{'SeqIn',true,25},{'SeqIn',false,125},{'SeqIn',false,225}],17}} =
- asn1_wrapper:decode('SeqOf','Seq3',lists:flatten(Bytes33)),
-
-
+main(_Rules) ->
+ SeqIn3 = [#'SeqIn'{boolIn=true,intIn=25},
+ #'SeqIn'{boolIn=false,intIn=125},
+ #'SeqIn'{boolIn=false,intIn=225}],
+
+ roundtrip('Seq1', #'Seq1'{bool1=true,int1=17},
+ #'Seq1'{bool1=true,int1=17,seq1=[]}),
+
+ roundtrip('Seq1', #'Seq1'{bool1=true,int1 = 17,
+ seq1=[#'SeqIn'{boolIn=true,
+ intIn=25}]}),
+ roundtrip('Seq1', #'Seq1'{bool1=true,
+ int1=17,
+ seq1=SeqIn3}),
+
+ roundtrip('Seq2', #'Seq2'{bool2=true,int2=17},
+ #'Seq2'{seq2=[],bool2=true,int2=17}),
+ roundtrip('Seq2',#'Seq2'{bool2=true,int2=17,
+ seq2=[#'SeqIn'{boolIn=true,
+ intIn=25}]}),
+ roundtrip('Seq2', #'Seq2'{bool2=true,
+ int2=17,
+ seq2=SeqIn3}),
+
+ roundtrip('Seq3', #'Seq3'{bool3=true,int3=17},
+ #'Seq3'{bool3=true,seq3=[],int3=17}),
+ roundtrip('Seq3',#'Seq3'{bool3=true,
+ int3=17,
+ seq3=[#'SeqIn'{boolIn=true,
+ intIn=25}]}),
+ roundtrip('Seq3', #'Seq3'{bool3=true,int3=17,seq3=SeqIn3}),
+
+ roundtrip('Seq4', #'Seq4'{}, #'Seq4'{seq41=[],seq42=[],seq43=[]}),
+
+ roundtrip('Seq4', #'Seq4'{seq41=[#'SeqIn'{boolIn=true,intIn=25}]},
+ #'Seq4'{seq41=[#'SeqIn'{boolIn=true,intIn=25}],
+ seq42=[],seq43=[]}),
+
+ roundtrip('Seq4', #'Seq4'{seq41=SeqIn3},
+ #'Seq4'{seq41=SeqIn3,seq42=[],seq43=[]}),
+ roundtrip('Seq4', #'Seq4'{seq42=[#'SeqIn'{boolIn=true,intIn=25}]},
+ #'Seq4'{seq41=[],seq42=[#'SeqIn'{boolIn=true,intIn=25}],
+ seq43=[]}),
+ roundtrip('Seq4', #'Seq4'{seq42=SeqIn3},
+ #'Seq4'{seq41=[],seq42=SeqIn3,seq43=[]}),
+
+ roundtrip('Seq4', #'Seq4'{seq43=[#'SeqIn'{boolIn=true,intIn=25}]},
+ #'Seq4'{seq41=[],seq42=[],
+ seq43=[#'SeqIn'{boolIn=true,intIn=25}]}),
+ roundtrip('Seq4', #'Seq4'{seq43=SeqIn3},
+ #'Seq4'{seq41=[],seq42=[],
+ seq43=SeqIn3}),
+
+ roundtrip('SeqEmp', #'SeqEmp'{seq1=[#'Empty'{}]}),
+
+ %% Test OTP-4590: correct encoding of the length of SEQUENC OF.
+ DayNames = ["Monday","Tuesday","Wednesday",
+ "Thursday","Friday","Saturday","Sunday"],
+ xroundtrip('DayNames1', 'DayNames3', DayNames),
+ xroundtrip('DayNames2', 'DayNames4', DayNames),
+ xroundtrip('DayNames2', 'DayNames4', [hd(DayNames)]),
+ xroundtrip('DayNames2', 'DayNames4', tl(DayNames)),
+ ok.
+roundtrip(T, V) ->
+ roundtrip(T, V, V).
-
-
- ?line {ok,Bytes41} = asn1_wrapper:encode('SeqOf','Seq4',#'Seq4'{}),
- ?line {ok,{'Seq4',[],[],[]}} = asn1_wrapper:decode('SeqOf','Seq4',lists:flatten(Bytes41)),
-
-
- ?line {ok,Bytes42} =
- asn1_wrapper:encode('SeqOf','Seq4',#'Seq4'{seq41 = [#'SeqIn'{boolIn = true,
- intIn = 25}]}),
- ?line {ok,{'Seq4',[{'SeqIn',true,25}],[],[]}} =
- asn1_wrapper:decode('SeqOf','Seq4',lists:flatten(Bytes42)),
-
-
- ?line {ok,Bytes43} =
- asn1_wrapper:encode('SeqOf','Seq4',#'Seq4'{seq41 = [#'SeqIn'{boolIn = true,
- intIn = 25},
- #'SeqIn'{boolIn = false,
- intIn = 125},
- #'SeqIn'{boolIn = false,
- intIn = 225}]}),
- ?line {ok,{'Seq4',[{'SeqIn',true,25},{'SeqIn',false,125},{'SeqIn',false,225}],[],[]}} =
- asn1_wrapper:decode('SeqOf','Seq4',lists:flatten(Bytes43)),
-
-
- ?line {ok,Bytes44} =
- asn1_wrapper:encode('SeqOf','Seq4',#'Seq4'{seq42 = [#'SeqIn'{boolIn = true,
- intIn = 25}]}),
- ?line {ok,{'Seq4',[],[{'SeqIn',true,25}],[]}} =
- asn1_wrapper:decode('SeqOf','Seq4',lists:flatten(Bytes44)),
-
-
- ?line {ok,Bytes45} =
- asn1_wrapper:encode('SeqOf','Seq4',#'Seq4'{seq42 = [#'SeqIn'{boolIn = true,
- intIn = 25},
- #'SeqIn'{boolIn = false,
- intIn = 125},
- #'SeqIn'{boolIn = false,
- intIn = 225}]}),
- ?line {ok,{'Seq4',[],[{'SeqIn',true,25},{'SeqIn',false,125},{'SeqIn',false,225}],[]}} =
- asn1_wrapper:decode('SeqOf','Seq4',lists:flatten(Bytes45)),
-
-
- ?line {ok,Bytes46} =
- asn1_wrapper:encode('SeqOf','Seq4',#'Seq4'{seq43 = [#'SeqIn'{boolIn = true,
- intIn = 25}]}),
- ?line {ok,{'Seq4',[],[],[{'SeqIn',true,25}]}} =
- asn1_wrapper:decode('SeqOf','Seq4',lists:flatten(Bytes46)),
-
-
- ?line {ok,Bytes47} =
- asn1_wrapper:encode('SeqOf','Seq4',#'Seq4'{seq43 = [#'SeqIn'{boolIn = true,
- intIn = 25},
- #'SeqIn'{boolIn = false,
- intIn = 125},
- #'SeqIn'{boolIn = false,
- intIn = 225}]}),
- ?line {ok,{'Seq4',[],[],[{'SeqIn',true,25},{'SeqIn',false,125},{'SeqIn',false,225}]}} =
- asn1_wrapper:decode('SeqOf','Seq4',lists:flatten(Bytes47)),
-
-
- ?line {ok,Bytes51} = asn1_wrapper:encode('SeqOf','SeqEmp',#'SeqEmp'{seq1 = [#'Empty'{}]}),
- ?line {ok,{'SeqEmp',[{'Empty'}]}} = asn1_wrapper:decode('SeqOf','SeqEmp',lists:flatten(Bytes51)),
-
- %% tests of OTP-4590
- case Rules of
- per ->
- DayNames = ["Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"],
- ?line {ok,Bytes60} = asn1_wrapper:encode('XSeqOf','DayNames2',DayNames),
- ?line {ok,Bytes60} = asn1_wrapper:encode('XSeqOf','DayNames4',DayNames),
- ?line {ok,DayNames} = asn1_wrapper:decode('XSeqOf','DayNames2',Bytes60),
- ?line {ok,DayNames} = asn1_wrapper:decode('XSeqOf','DayNames4',Bytes60),
- ?line {ok,Bytes61} = asn1_wrapper:encode('XSeqOf','DayNames1',DayNames),
- ?line {ok,Bytes61} = asn1_wrapper:encode('XSeqOf','DayNames3',DayNames),
- ?line {ok,DayNames} = asn1_wrapper:decode('XSeqOf','DayNames1',Bytes61),
- ?line {ok,DayNames} = asn1_wrapper:decode('XSeqOf','DayNames3',Bytes61);
- _ ->
- ok
- end,
-
+roundtrip(Type, Val, Expected) ->
+ M = 'SeqOf',
+ {ok,Enc} = M:encode(Type, Val),
+ {ok,Expected} = M:decode(Type, Enc),
ok.
-
+xroundtrip(T1, T2, Val) ->
+ M = 'XSeqOf',
+ {ok,Enc} = M:encode(T1, Val),
+ {ok,Enc} = M:encode(T2, Val),
+ {ok,Val} = M:decode(T1, Enc),
+ {ok,Val} = M:decode(T2, Enc),
+ ok.