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

« back to all changes in this revision

Viewing changes to lib/debugger/test/bs_match_misc_SUITE.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 2000-2011. 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(bs_match_misc_SUITE).
 
21
 
 
22
-author('bjorn@erix.ericsson.se').
 
23
-export([all/0, suite/0,groups/0,init_per_group/2,end_per_group/2,
 
24
         init_per_testcase/2,end_per_testcase/2,
 
25
         init_per_suite/1,end_per_suite/1,
 
26
         bound_var/1,bound_tail/1,t_float/1,little_float/1,sean/1]).
 
27
 
 
28
-include_lib("test_server/include/test_server.hrl").
 
29
 
 
30
suite() -> [{ct_hooks,[ts_install_cth]}].
 
31
 
 
32
all() -> 
 
33
    cases().
 
34
 
 
35
groups() -> 
 
36
    [].
 
37
 
 
38
init_per_group(_GroupName, Config) ->
 
39
    Config.
 
40
 
 
41
end_per_group(_GroupName, Config) ->
 
42
    Config.
 
43
 
 
44
 
 
45
cases() -> 
 
46
    [bound_var, bound_tail, t_float, little_float, sean].
 
47
 
 
48
init_per_testcase(_Case, Config) ->
 
49
    test_lib:interpret(?MODULE),
 
50
    Dog = test_server:timetrap(?t:minutes(1)),
 
51
    [{watchdog,Dog}|Config].
 
52
 
 
53
end_per_testcase(_Case, Config) ->
 
54
    Dog = ?config(watchdog, Config),
 
55
    ?t:timetrap_cancel(Dog),
 
56
    ok.
 
57
 
 
58
init_per_suite(Config) when is_list(Config) ->
 
59
    ?line test_lib:interpret(?MODULE),
 
60
    ?line true = lists:member(?MODULE, int:interpreted()),
 
61
    Config.
 
62
 
 
63
end_per_suite(Config) when is_list(Config) ->
 
64
    ok.
 
65
 
 
66
bound_var(doc) -> "Test matching of bound variables.";
 
67
bound_var(Config) when list(Config) ->
 
68
    ?line ok = bound_var(42, 13, <<42,13>>),
 
69
    ?line nope = bound_var(42, 13, <<42,255>>),
 
70
    ?line nope = bound_var(42, 13, <<154,255>>),
 
71
    ok.
 
72
 
 
73
bound_var(A, B, <<A:8,B:8>>) -> ok;
 
74
bound_var(_, _, _) -> nope.
 
75
 
 
76
bound_tail(doc) -> "Test matching of a bound tail.";
 
77
bound_tail(Config) when list(Config) ->
 
78
    ?line ok = bound_tail(<<>>, <<13,14>>),
 
79
    ?line ok = bound_tail(<<2,3>>, <<1,1,2,3>>),
 
80
    ?line nope = bound_tail(<<2,3>>, <<1,1,2,7>>),
 
81
    ?line nope = bound_tail(<<2,3>>, <<1,1,2,3,4>>),
 
82
    ?line nope = bound_tail(<<2,3>>, <<>>),
 
83
    ok.
 
84
 
 
85
bound_tail(T, <<_:16,T/binary>>) -> ok;
 
86
bound_tail(_, _) -> nope.
 
87
 
 
88
t_float(Config) when list(Config) ->
 
89
    F = f1(),
 
90
    G = f_one(),
 
91
 
 
92
    ?line G = match_float(<<63,128,0,0>>, 32, 0),
 
93
    ?line G = match_float(<<63,240,0,0,0,0,0,0>>, 64, 0),
 
94
 
 
95
    ?line fcmp(F, match_float(<<F:32/float>>, 32, 0)),
 
96
    ?line fcmp(F, match_float(<<F:64/float>>, 64, 0)),
 
97
    ?line fcmp(F, match_float(<<1:1,F:32/float,127:7>>, 32, 1)),
 
98
    ?line fcmp(F, match_float(<<1:1,F:64/float,127:7>>, 64, 1)),
 
99
    ?line fcmp(F, match_float(<<1:13,F:32/float,127:3>>, 32, 13)),
 
100
    ?line fcmp(F, match_float(<<1:13,F:64/float,127:3>>, 64, 13)),
 
101
    ok.
 
102
 
 
103
 
 
104
fcmp(F1, F2) when (F1 - F2) / F2 < 0.0000001 -> ok.
 
105
 
 
106
match_float(Bin0, Fsz, I) ->
 
107
    Bin = make_sub_bin(Bin0),
 
108
    Bsz = size(Bin) * 8,
 
109
    Tsz = Bsz - Fsz - I,
 
110
    <<_:I,F:Fsz/float,_:Tsz>> = Bin,
 
111
    F.
 
112
 
 
113
little_float(Config) when list(Config) ->
 
114
    F = f2(),
 
115
    G = f_one(),
 
116
 
 
117
    ?line G = match_float_little(<<0,0,0,0,0,0,240,63>>, 64, 0),
 
118
    ?line G = match_float_little(<<0,0,128,63>>, 32, 0),
 
119
 
 
120
    ?line fcmp(F, match_float_little(<<F:32/float-little>>, 32, 0)),
 
121
    ?line fcmp(F, match_float_little(<<F:64/float-little>>, 64, 0)),
 
122
    ?line fcmp(F, match_float_little(<<1:1,F:32/float-little,127:7>>, 32, 1)),
 
123
    ?line fcmp(F, match_float_little(<<1:1,F:64/float-little,127:7>>, 64, 1)),
 
124
    ?line fcmp(F, match_float_little(<<1:13,F:32/float-little,127:3>>, 32, 13)),
 
125
    ?line fcmp(F, match_float_little(<<1:13,F:64/float-little,127:3>>, 64, 13)),
 
126
 
 
127
    ok.
 
128
 
 
129
match_float_little(Bin0, Fsz, I) ->
 
130
    Bin = make_sub_bin(Bin0),
 
131
    Bsz = size(Bin) * 8,
 
132
    Tsz = Bsz - Fsz - I,
 
133
    <<_:I,F:Fsz/float-little,_:Tsz>> = Bin,
 
134
    F.
 
135
 
 
136
 
 
137
make_sub_bin(Bin0) ->
 
138
    Sz = size(Bin0),
 
139
    Bin1 = <<37,Bin0/binary,38,39>>,
 
140
    <<_:8,Bin:Sz/binary,_:8,_:8>> = Bin1,
 
141
    Bin.
 
142
 
 
143
f1() ->
 
144
    3.1415.
 
145
 
 
146
f2() ->
 
147
    2.7133.
 
148
 
 
149
f_one() ->
 
150
    1.0.
 
151
 
 
152
sean(Config) when list(Config) ->
 
153
    ?line small = sean1(<<>>),
 
154
    ?line small = sean1(<<1>>),
 
155
    ?line small = sean1(<<1,2>>),
 
156
    ?line small = sean1(<<1,2,3>>),
 
157
    ?line large = sean1(<<1,2,3,4>>),
 
158
 
 
159
    ?line small = sean1(<<4>>),
 
160
    ?line small = sean1(<<4,5>>),
 
161
    ?line small = sean1(<<4,5,6>>),
 
162
    ?line {'EXIT',{function_clause,_}} = (catch sean1(<<4,5,6,7>>)),
 
163
    ok.
 
164
 
 
165
sean1(<<B/binary>>) when size(B) < 4 -> small;
 
166
sean1(<<1, _B/binary>>) -> large.