1%%
2%% %CopyrightBegin%
3%%
4%% Copyright Ericsson AB 2001-2018. 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-module(overridden_bif_SUITE).
21-compile({no_auto_import,[is_reference/1,size/1]}).
22
23-export([all/0, suite/0,groups/0,init_per_suite/1, end_per_suite/1,
24	 init_per_group/2,end_per_group/2,
25	 init_per_testcase/2,end_per_testcase/2,
26	 overridden_bif/1]).
27
28-include_lib("common_test/include/ct.hrl").
29
30%% Used by overridden_bif/1.
31-import(gb_sets, [size/1]).
32-import(test_lib, [binary/1]).
33
34suite() ->
35    [{ct_hooks,[ts_install_cth]},
36     {timetrap,{minutes,1}}].
37
38all() ->
39    [{group,p}].
40
41groups() ->
42    [{p,test_lib:parallel(),
43      [overridden_bif
44      ]}].
45
46init_per_suite(Config) ->
47    test_lib:recompile(?MODULE),
48    Config.
49
50end_per_suite(_Config) ->
51    ok.
52
53init_per_group(_GroupName, Config) ->
54    Config.
55
56end_per_group(_GroupName, Config) ->
57    Config.
58
59
60init_per_testcase(Case, Config) when is_atom(Case), is_list(Config) ->
61    Config.
62
63end_per_testcase(Case, Config) when is_atom(Case), is_list(Config) ->
64    ok.
65
66overridden_bif(_Config) ->
67    L = [-3,-2,-1,0,1,2,3,4],
68    [-3,0,3] = do_overridden_bif_1(L),
69    [-2,0,2,4] = do_overridden_bif_2(L),
70    [3] = do_overridden_bif_3(L),
71    [2,4] = do_overridden_bif_4(L),
72
73    Set = gb_sets:from_list(L),
74    [Set] = do_overridden_bif_5([gb_sets:singleton(42),Set]),
75
76    [100,0] = do_overridden_bif_6([100|L]),
77    ok.
78
79do_overridden_bif_1(L) ->
80    [E || E <- L, is_reference(E)].
81
82do_overridden_bif_2(L) ->
83    [E || E <- L, port(E)].
84
85do_overridden_bif_3(L) ->
86    [E || E <- L, (is_reference(E) andalso E > 0)].
87
88do_overridden_bif_4(L) ->
89    [E || E <- L, (port(E) andalso E > 0)].
90
91do_overridden_bif_5(L) ->
92    [E || E <- L, size(E) > 1].
93
94do_overridden_bif_6(L) ->
95    [E || E <- L, binary(E)].
96
97is_reference(N) ->
98    N rem 3 =:= 0.
99
100port(N) ->
101    N rem 2 =:= 0.
102