1%%
2%% %CopyrightBegin%
3%%
4%% Copyright Ericsson AB 1997-2016. All Rights Reserved.
5%%
6%% Licensed under the Apache License, Version 2.0 (the "License");
7%% you may not use this file except in compliance with the License.
8%% You may obtain a copy of the License at
9%%
10%%     http://www.apache.org/licenses/LICENSE-2.0
11%%
12%% Unless required by applicable law or agreed to in writing, software
13%% distributed under the License is distributed on an "AS IS" BASIS,
14%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15%% See the License for the specific language governing permissions and
16%% limitations under the License.
17%%
18%% %CopyrightEnd%
19%%
20%%
21-module(testSetOf).
22
23-export([main/1]).
24
25-include_lib("common_test/include/ct.hrl").
26
27-record('Set1',{bool1, int1, set1 = asn1_DEFAULT}).
28-record('Set2',{set2 = asn1_DEFAULT, bool2, int2}).
29-record('Set3',{bool3, set3 = asn1_DEFAULT, int3}).
30-record('Set4',{set41 = asn1_DEFAULT, set42 = asn1_DEFAULT, set43 = asn1_DEFAULT}).
31-record('SetIn',{boolIn, intIn}).
32-record('SetEmp',{set1}).
33-record('Empty',{}).
34
35
36
37main(_Rules) ->
38    roundtrip('Set1',
39	      #'Set1'{bool1=true,int1=17,set1=asn1_DEFAULT},
40	      #'Set1'{bool1=true,int1=17,set1=[]}),
41    roundtrip('Set1',
42	      #'Set1'{bool1=true,int1=17,
43		      set1=[#'SetIn'{boolIn=true,intIn=25}]}),
44    roundtrip('Set1', #'Set1'{bool1=true,int1=17,
45			      set1=[#'SetIn'{boolIn=true,intIn=25},
46				    #'SetIn'{boolIn=false,intIn=125},
47				    #'SetIn'{boolIn=false,intIn=225}]}),
48
49    roundtrip('Set2',
50	      #'Set2'{set2=asn1_DEFAULT,bool2=true,int2=17},
51	      #'Set2'{set2=[],bool2=true,int2=17}),
52    roundtrip('Set2',
53	      #'Set2'{set2=[#'SetIn'{boolIn=true,intIn=25}],
54		      bool2=true,int2=17}),
55    roundtrip('Set2',
56	      #'Set2'{set2=[#'SetIn'{boolIn=true,intIn=25},
57			    #'SetIn'{boolIn=false,intIn=125},
58			    #'SetIn'{boolIn=false,intIn=225}],
59		      bool2=true,int2=17}),
60
61    roundtrip('Set3',
62	      #'Set3'{bool3=true,set3=asn1_DEFAULT,int3=17},
63	      #'Set3'{bool3=true,set3=[],int3=17}),
64    roundtrip('Set3',
65	      #'Set3'{bool3=true,set3=[#'SetIn'{boolIn=true,intIn=25}],
66		      int3=17}),
67    roundtrip('Set3',
68	      #'Set3'{bool3=true,
69		      set3=[#'SetIn'{boolIn=true,intIn=25},
70			    #'SetIn'{boolIn=false,intIn=125},
71			    #'SetIn'{boolIn=false,intIn=225}],
72		      int3=17}),
73
74    roundtrip('Set4',
75	      #'Set4'{set41=asn1_DEFAULT,set42=asn1_DEFAULT,
76		      set43=asn1_DEFAULT},
77	      #'Set4'{set41=[],set42=[],set43=[]}),
78    roundtrip('Set4',
79	      #'Set4'{set41=[#'SetIn'{boolIn=true,intIn=25}],
80		      set42=asn1_DEFAULT,set43=asn1_DEFAULT},
81	      #'Set4'{set41=[#'SetIn'{boolIn=true,intIn=25}],
82		      set42=[],set43=[]}),
83    roundtrip('Set4',
84	      #'Set4'{set41=[#'SetIn'{boolIn=true,intIn=25},
85			     #'SetIn'{boolIn=false,intIn=125},
86			     #'SetIn'{boolIn=false,intIn=225}],
87		      set42=asn1_DEFAULT,set43=asn1_DEFAULT},
88	      #'Set4'{set41=[#'SetIn'{boolIn=true,intIn=25},
89			     #'SetIn'{boolIn=false,intIn=125},
90			     #'SetIn'{boolIn=false,intIn=225}],
91		      set42=[],set43=[]}),
92    roundtrip('Set4',
93	      #'Set4'{set41=asn1_DEFAULT,
94		      set42=[#'SetIn'{boolIn=true,intIn=25}],
95		      set43=asn1_DEFAULT},
96	      #'Set4'{set41=[],
97		      set42=[#'SetIn'{boolIn=true,intIn=25}],
98		      set43=[]}),
99    roundtrip('Set4',
100	      #'Set4'{set41=asn1_DEFAULT,
101		      set42=[#'SetIn'{boolIn=true,intIn=25},
102			     #'SetIn'{boolIn=false,intIn=125},
103			     #'SetIn'{boolIn=false,intIn=225}],
104		      set43=asn1_DEFAULT},
105	      #'Set4'{set41=[],
106		      set42=[#'SetIn'{boolIn=true,intIn=25},
107			     #'SetIn'{boolIn=false,intIn=125},
108			     #'SetIn'{boolIn=false,intIn=225}],
109		      set43=[]}),
110    roundtrip('Set4',
111	      #'Set4'{set41=asn1_DEFAULT,set42=asn1_DEFAULT,
112		      set43=[#'SetIn'{boolIn=true,intIn=25}]},
113	      #'Set4'{set41=[],set42=[],
114		      set43=[#'SetIn'{boolIn=true,intIn=25}]}),
115    roundtrip('Set4',
116	      #'Set4'{set41=asn1_DEFAULT,set42=asn1_DEFAULT,
117		      set43=[#'SetIn'{boolIn=true,intIn=25},
118			     #'SetIn'{boolIn=false,intIn=125},
119			     #'SetIn'{boolIn=false,intIn=225}]},
120	      #'Set4'{set41=[],set42=[],
121		      set43=[#'SetIn'{boolIn=true,intIn=25},
122			     #'SetIn'{boolIn=false,intIn=125},
123			     #'SetIn'{boolIn=false,intIn=225}]}),
124
125    roundtrip('SetOs', [<<"First">>,<<"Second">>,<<"Third">>]),
126    roundtrip('SetOsImp', [<<"First">>,<<"Second">>,<<"Third">>]),
127    roundtrip('SetOsExp', [<<"First">>,<<"Second">>,<<"Third">>]),
128    roundtrip('SetEmp', #'SetEmp'{set1=[#'Empty'{}]}),
129
130    ok.
131
132roundtrip(T, V) ->
133    roundtrip(T, V, V).
134
135roundtrip(Type, Value, ExpectedValue) ->
136    asn1_test_lib:roundtrip('SetOf', Type, Value, ExpectedValue).
137