aboutsummaryrefslogtreecommitdiffstats
path: root/lib/asn1/test/testSeqOf.erl
blob: 771045f9af21f5cce49d22afbbd84bfc5f361969 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
%%
%% %CopyrightBegin%
%%
%% Copyright Ericsson AB 1997-2012. All Rights Reserved.
%%
%% The contents of this file are subject to the Erlang Public License,
%% Version 1.1, (the "License"); you may not use this file except in
%% compliance with the License. You should have received a copy of the
%% Erlang Public License along with this software. If not, it can be
%% retrieved online at http://www.erlang.org/.
%%
%% Software distributed under the License is distributed on an "AS IS"
%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
%% the License for the specific language governing rights and limitations
%% under the License.
%%
%% %CopyrightEnd%
%%
%%
-module(testSeqOf).

-export([main/1]).

-include_lib("test_server/include/test_server.hrl").

-record('Seq1',{bool1, int1, seq1 = asn1_DEFAULT}).
-record('Seq2',{seq2 = asn1_DEFAULT, bool2, int2}).
-record('Seq3',{bool3, seq3 = asn1_DEFAULT, int3}).
-record('Seq4',{seq41 = asn1_DEFAULT, seq42 = asn1_DEFAULT, seq43 = asn1_DEFAULT}).
-record('SeqIn',{boolIn, intIn}).
-record('SeqEmp',{seq1}).
-record('Empty',{}).

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).

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.