~ubuntu-branches/ubuntu/trusty/erlang/trusty

« back to all changes in this revision

Viewing changes to lib/asn1/test/testSetOptional.erl

  • Committer: Bazaar Package Importer
  • Author(s): Clint Byrum
  • Date: 2011-05-05 15:48:43 UTC
  • mfrom: (3.5.13 sid)
  • Revision ID: james.westby@ubuntu.com-20110505154843-0om6ekzg6m7ugj27
Tags: 1:14.b.2-dfsg-3ubuntu1
* Merge from debian unstable.  Remaining changes:
  - Drop libwxgtk2.8-dev build dependency. Wx isn't in main, and not
    supposed to.
  - Drop erlang-wx binary.
  - Drop erlang-wx dependency from -megaco, -common-test, and -reltool, they
    do not really need wx. Also drop it from -debugger; the GUI needs wx,
    but it apparently has CLI bits as well, and is also needed by -megaco,
    so let's keep the package for now.
  - debian/patches/series: Do what I meant, and enable build-options.patch
    instead.
* Additional changes:
  - Drop erlang-wx from -et
* Dropped Changes:
  - patches/pcre-crash.patch: CVE-2008-2371: outer level option with
    alternatives caused crash. (Applied Upstream)
  - fix for ssl certificate verification in newSSL: 
    ssl_cacertfile_fix.patch (Applied Upstream)
  - debian/patches/series: Enable native.patch again, to get stripped beam
    files and reduce the package size again. (build-options is what
    actually accomplished this)
  - Remove build-options.patch on advice from upstream and because it caused
    odd build failures.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
%%
 
2
%% %CopyrightBegin%
 
3
%%
 
4
%% Copyright Ericsson AB 1997-2010. All Rights Reserved.
 
5
%%
 
6
%% The contents of this file are subject to the Erlang Public License,
 
7
%% Version 1.1, (the "License"); you may not use this file except in
 
8
%% compliance with the License. You should have received a copy of the
 
9
%% Erlang Public License along with this software. If not, it can be
 
10
%% retrieved online at http://www.erlang.org/.
 
11
%%
 
12
%% Software distributed under the License is distributed on an "AS IS"
 
13
%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
 
14
%% the License for the specific language governing rights and limitations
 
15
%% under the License.
 
16
%%
 
17
%% %CopyrightEnd%
 
18
%%
 
19
%%
 
20
-module(testSetOptional).
 
21
 
 
22
-include("External.hrl").
 
23
-export([compile/3]).
 
24
-export([main/1]).
 
25
-export([ticket_7533/1,decoder/4]).
 
26
-include_lib("test_server/include/test_server.hrl").
 
27
 
 
28
-record('SetOpt1',{bool1 = asn1_NOVALUE, int1, set1 = asn1_NOVALUE}).
 
29
-record('SetOpt1Imp',{bool1 = asn1_NOVALUE, int1, set1 = asn1_NOVALUE}).
 
30
-record('SetOpt1Exp',{bool1 = asn1_NOVALUE, int1, set1 = asn1_NOVALUE}).
 
31
-record('SetOpt2',{set2 = asn1_NOVALUE, bool2, int2}).
 
32
-record('SetOpt2Imp',{set2 = asn1_NOVALUE, bool2, int2}).
 
33
-record('SetOpt2Exp',{set2 = asn1_NOVALUE, bool2, int2}).
 
34
-record('SetOpt3',{bool3 = asn1_NOVALUE, set3 = asn1_NOVALUE, int3 = asn1_NOVALUE}).
 
35
-record('SetOpt3Imp',{bool3 = asn1_NOVALUE, set3 = asn1_NOVALUE, int3 = asn1_NOVALUE}).
 
36
-record('SetOpt3Exp',{bool3 = asn1_NOVALUE, set3 = asn1_NOVALUE, int3 = asn1_NOVALUE}).
 
37
-record('SetIn',{boolIn, intIn}).
 
38
 
 
39
 
 
40
compile(Config,Rules,Options) ->
 
41
 
 
42
    ?line DataDir = ?config(data_dir,Config),
 
43
    ?line OutDir = ?config(priv_dir,Config),
 
44
    ?line true = code:add_patha(?config(priv_dir,Config)),
 
45
    ?line ok = asn1ct:compile(DataDir ++ "SetOptional",[Rules,{outdir,OutDir}]++Options).
 
46
 
 
47
 
 
48
 
 
49
main(_Rules) ->
 
50
    
 
51
    ?line {ok,Bytes11} = 
 
52
        asn1_wrapper:encode('SetOptional','SetOpt1',#'SetOpt1'{bool1 = true,
 
53
                                                        int1 = 15,
 
54
                                                        set1 = #'SetIn'{boolIn = true,
 
55
                                                                        intIn = 66}}), 
 
56
    ?line {ok,{'SetOpt1',true,15,{'SetIn',true,66}}} = 
 
57
        asn1_wrapper:decode('SetOptional','SetOpt1',lists:flatten(Bytes11)),
 
58
    
 
59
    
 
60
    ?line {ok,Bytes12} = asn1_wrapper:encode('SetOptional','SetOpt1',#'SetOpt1'{int1 = 15}), 
 
61
    ?line {ok,{'SetOpt1',asn1_NOVALUE,15,asn1_NOVALUE}} = 
 
62
        asn1_wrapper:decode('SetOptional','SetOpt1',lists:flatten(Bytes12)),
 
63
    
 
64
    
 
65
    ?line {ok,Bytes21} = 
 
66
        asn1_wrapper:encode('SetOptional','SetOpt2',#'SetOpt2'{bool2 = true,
 
67
                                                        int2 = 15,
 
68
                                                        set2 = #'SetIn'{boolIn = true,
 
69
                                                                        intIn = 66}}), 
 
70
    ?line {ok,{'SetOpt2',{'SetIn',true,66},true,15}} = 
 
71
        asn1_wrapper:decode('SetOptional','SetOpt2',lists:flatten(Bytes21)),
 
72
    
 
73
    
 
74
    ?line {ok,Bytes22} = asn1_wrapper:encode('SetOptional','SetOpt2',#'SetOpt2'{int2 = 15,
 
75
                                                                          bool2 = true}), 
 
76
    ?line {ok,{'SetOpt2',asn1_NOVALUE,true,15}} = 
 
77
        asn1_wrapper:decode('SetOptional','SetOpt2',lists:flatten(Bytes22)),
 
78
    
 
79
    
 
80
    
 
81
    ?line {ok,Bytes31} = 
 
82
        asn1_wrapper:encode('SetOptional','SetOpt3',#'SetOpt3'{bool3 = true,
 
83
                                                        int3 = 15,
 
84
                                                        set3 = #'SetIn'{boolIn = true,
 
85
                                                                        intIn = 66}}), 
 
86
    ?line {ok,{'SetOpt3',true,{'SetIn',true,66},15}} = 
 
87
        asn1_wrapper:decode('SetOptional','SetOpt3',lists:flatten(Bytes31)),
 
88
    
 
89
    
 
90
    ?line {ok,Bytes32} = asn1_wrapper:encode('SetOptional','SetOpt3',#'SetOpt3'{int3 = 15}), 
 
91
    ?line {ok,{'SetOpt3',asn1_NOVALUE,asn1_NOVALUE,15}} = 
 
92
        asn1_wrapper:decode('SetOptional','SetOpt3',lists:flatten(Bytes32)),
 
93
    
 
94
    
 
95
    
 
96
    
 
97
    
 
98
    ?line {ok,Bytes41} = 
 
99
        asn1_wrapper:encode('SetOptional','SetOpt1Imp',#'SetOpt1Imp'{bool1 = true,
 
100
                                                              int1 = 15,
 
101
                                                              set1 = #'SetIn'{boolIn = true,
 
102
                                                                              intIn = 66}}), 
 
103
    ?line {ok,{'SetOpt1Imp',true,15,{'SetIn',true,66}}} = 
 
104
        asn1_wrapper:decode('SetOptional','SetOpt1Imp',lists:flatten(Bytes41)),
 
105
    
 
106
    
 
107
    ?line {ok,Bytes42} = asn1_wrapper:encode('SetOptional','SetOpt1Imp',#'SetOpt1Imp'{int1 = 15}), 
 
108
    ?line {ok,{'SetOpt1Imp',asn1_NOVALUE,15,asn1_NOVALUE}} = 
 
109
        asn1_wrapper:decode('SetOptional','SetOpt1Imp',lists:flatten(Bytes42)),
 
110
    
 
111
    
 
112
    ?line {ok,Bytes51} = 
 
113
        asn1_wrapper:encode('SetOptional','SetOpt2Imp',#'SetOpt2Imp'{bool2 = true,
 
114
                                                              int2 = 15,
 
115
                                                              set2 = #'SetIn'{boolIn = true,
 
116
                                                                              intIn = 66}}), 
 
117
    ?line {ok,{'SetOpt2Imp',{'SetIn',true,66},true,15}} = 
 
118
        asn1_wrapper:decode('SetOptional','SetOpt2Imp',lists:flatten(Bytes51)),
 
119
    
 
120
    
 
121
    ?line {ok,Bytes52} = asn1_wrapper:encode('SetOptional','SetOpt2Imp',#'SetOpt2Imp'{int2 = 15,
 
122
                                                                                bool2 = true}), 
 
123
    ?line {ok,{'SetOpt2Imp',asn1_NOVALUE,true,15}} = 
 
124
        asn1_wrapper:decode('SetOptional','SetOpt2Imp',lists:flatten(Bytes52)),
 
125
    
 
126
    
 
127
    
 
128
    ?line {ok,Bytes61} = 
 
129
        asn1_wrapper:encode('SetOptional','SetOpt3Imp',#'SetOpt3Imp'{bool3 = true,
 
130
                                                              int3 = 15,
 
131
                                                              set3 = #'SetIn'{boolIn = true,
 
132
                                                                              intIn = 66}}), 
 
133
    ?line {ok,{'SetOpt3Imp',true,{'SetIn',true,66},15}} = 
 
134
        asn1_wrapper:decode('SetOptional','SetOpt3Imp',lists:flatten(Bytes61)),
 
135
    
 
136
    
 
137
    ?line {ok,Bytes62} = asn1_wrapper:encode('SetOptional','SetOpt3Imp',#'SetOpt3Imp'{int3 = 15}), 
 
138
    ?line {ok,{'SetOpt3Imp',asn1_NOVALUE,asn1_NOVALUE,15}} = 
 
139
        asn1_wrapper:decode('SetOptional','SetOpt3Imp',lists:flatten(Bytes62)),
 
140
    
 
141
    
 
142
    
 
143
    
 
144
    
 
145
    
 
146
    ?line {ok,Bytes71} = 
 
147
        asn1_wrapper:encode('SetOptional','SetOpt1Exp',#'SetOpt1Exp'{bool1 = true,
 
148
                                                              int1 = 15,
 
149
                                                              set1 = #'SetIn'{boolIn = true,
 
150
                                                                              intIn = 66}}), 
 
151
    ?line {ok,{'SetOpt1Exp',true,15,{'SetIn',true,66}}} = 
 
152
        asn1_wrapper:decode('SetOptional','SetOpt1Exp',lists:flatten(Bytes71)),
 
153
    
 
154
    
 
155
    ?line {ok,Bytes72} = asn1_wrapper:encode('SetOptional','SetOpt1Exp',#'SetOpt1Exp'{int1 = 15}), 
 
156
    ?line {ok,{'SetOpt1Exp',asn1_NOVALUE,15,asn1_NOVALUE}} = 
 
157
        asn1_wrapper:decode('SetOptional','SetOpt1Exp',lists:flatten(Bytes72)),
 
158
    
 
159
    
 
160
    ?line {ok,Bytes81} = 
 
161
        asn1_wrapper:encode('SetOptional','SetOpt2Exp',#'SetOpt2Exp'{bool2 = true,
 
162
                                                              int2 = 15,
 
163
                                                              set2 = #'SetIn'{boolIn = true,
 
164
                                                                              intIn = 66}}), 
 
165
    ?line {ok,{'SetOpt2Exp',{'SetIn',true,66},true,15}} = 
 
166
        asn1_wrapper:decode('SetOptional','SetOpt2Exp',lists:flatten(Bytes81)),
 
167
    
 
168
    
 
169
    ?line {ok,Bytes82} = asn1_wrapper:encode('SetOptional','SetOpt2Exp',#'SetOpt2Exp'{int2 = 15,
 
170
                                                                               bool2 = true}), 
 
171
    ?line {ok,{'SetOpt2Exp',asn1_NOVALUE,true,15}} = 
 
172
        asn1_wrapper:decode('SetOptional','SetOpt2Exp',lists:flatten(Bytes82)),
 
173
    
 
174
    
 
175
    
 
176
    ?line {ok,Bytes91} = 
 
177
        asn1_wrapper:encode('SetOptional','SetOpt3Exp',#'SetOpt3Exp'{bool3 = true,
 
178
                                                              int3 = 15,
 
179
                                                              set3 = #'SetIn'{boolIn = true,
 
180
                                                                              intIn = 66}}), 
 
181
    ?line {ok,{'SetOpt3Exp',true,{'SetIn',true,66},15}} = 
 
182
        asn1_wrapper:decode('SetOptional','SetOpt3Exp',lists:flatten(Bytes91)),
 
183
    
 
184
    
 
185
    ?line {ok,Bytes92} = asn1_wrapper:encode('SetOptional','SetOpt3Exp',#'SetOpt3Exp'{int3 = 15}), 
 
186
    ?line {ok,{'SetOpt3Exp',asn1_NOVALUE,asn1_NOVALUE,15}} = 
 
187
        asn1_wrapper:decode('SetOptional','SetOpt3Exp',lists:flatten(Bytes92)),
 
188
    
 
189
    
 
190
    
 
191
    
 
192
    ok.
 
193
 
 
194
 
 
195
ticket_7533(Ber) when Ber == ber; Ber == ber_bin ->
 
196
    Val = #'SetOpt1'{bool1 = true,int1=12,set1=#'SetIn'{boolIn=false,intIn=13}},
 
197
    ?line {ok,B} = asn1_wrapper:encode('SetOptional','SetOpt1',Val),
 
198
    ?line {ok,Val} = asn1_wrapper:decode('SetOptional','SetOpt1',B),
 
199
    
 
200
    CorruptVal = [49,14,1,1,255,2,1,12] ++ lists:duplicate(8,0),
 
201
    Pid = spawn(?MODULE,decoder,[self(),'SetOptional','SetOpt1',CorruptVal]),
 
202
    receive
 
203
        {ok,Pid,Result} ->
 
204
            io:format("Decode result: ~p~n",[Result]),
 
205
            ok
 
206
    after 10000 ->
 
207
            exit(Pid,normal),
 
208
            io:format("Decode timeout~n",[]),
 
209
            error
 
210
    end;
 
211
ticket_7533(_) ->
 
212
    ok.
 
213
 
 
214
decoder(Parent,Module,Type,Val) ->
 
215
    io:format("Decoding~n",[]),
 
216
    ?line {ok,Res} = asn1_wrapper:decode(Module,Type,Val),
 
217
    io:format("Decode res: ~p~n",[Res]),
 
218
    Parent ! {ok,self(),Res}.