1: %%
    2: %% %CopyrightBegin%
    3: %%
    4: %% Copyright Ericsson AB 2007-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: %%
   21: %% Originally based on Per Gustafsson's test suite.
   22: %%
   23: 
   24: -module(bs_bincomp_SUITE).
   25: 
   26: -export([all/0, suite/0,groups/0,init_per_suite/1, end_per_suite/1, 
   27: 	 init_per_group/2,end_per_group/2,
   28: 	 init_per_testcase/2,end_per_testcase/2,
   29: 	 byte_aligned/1,bit_aligned/1,extended_byte_aligned/1,
   30: 	 extended_bit_aligned/1,mixed/1]).
   31: 
   32: -include_lib("test_server/include/test_server.hrl").
   33: 
   34: init_per_testcase(_Case, Config) ->
   35:     test_lib:interpret(?MODULE),
   36:     Dog = test_server:timetrap(?t:minutes(1)),
   37:     [{watchdog,Dog}|Config].
   38: 
   39: end_per_testcase(_Case, Config) ->
   40:     Dog = ?config(watchdog, Config),
   41:     ?t:timetrap_cancel(Dog),
   42:     ok.
   43: 
   44: suite() -> [{ct_hooks,[ts_install_cth]}].
   45: 
   46: all() -> 
   47:     [byte_aligned, bit_aligned, extended_byte_aligned,
   48:      extended_bit_aligned, mixed].
   49: 
   50: groups() -> 
   51:     [].
   52: 
   53: init_per_suite(Config) ->
   54:     Config.
   55: 
   56: end_per_suite(_Config) ->
   57:     ok.
   58: 
   59: init_per_group(_GroupName, Config) ->
   60:     Config.
   61: 
   62: end_per_group(_GroupName, Config) ->
   63:     Config.
   64: 
   65: 
   66: 
   67: byte_aligned(Config) when is_list(Config) ->
   68:     ?line <<"abcdefg">> = << <<(X+32)>> || <<X>> <= <<"ABCDEFG">> >>,
   69:     ?line <<1:32/little,2:32/little,3:32/little,4:32/little>> =
   70: 	<< <<X:32/little>> || <<X:32>> <= <<1:32,2:32,3:32,4:32>> >>,
   71:     ?line <<1:32/little,2:32/little,3:32/little,4:32/little>> =
   72: 	<< <<X:32/little>> || <<X:16>> <= <<1:16,2:16,3:16,4:16>> >>,
   73:   ok.
   74: 
   75: bit_aligned(Config) when is_list(Config) ->
   76:     ?line <<$a:7,$b:7,$c:7,$d:7,$e:7,$f:7,$g:7>> =
   77: 	<< <<(X+32):7>> || <<X>> <= <<"ABCDEFG">> >>,
   78:     ?line <<"ABCDEFG">> =
   79: 	<< <<(X-32)>> || <<X:7>> <= <<$a:7,$b:7,$c:7,$d:7,$e:7,$f:7,$g:7>> >>,
   80:     ?line <<1:31/little,2:31/little,3:31/little,4:31/little>> =
   81: 	<< <<X:31/little>> || <<X:31>> <= <<1:31,2:31,3:31,4:31>> >>,
   82:     ?line <<1:31/little,2:31/little,3:31/little,4:31/little>> =
   83: 	<< <<X:31/little>> || <<X:15>> <= <<1:15,2:15,3:15,4:15>> >>,
   84:   ok.
   85: 
   86: extended_byte_aligned(Config) when is_list(Config) ->
   87:     ?line <<"abcdefg">> = << <<(X+32)>> || X <- "ABCDEFG" >>,
   88:     ?line "abcdefg" = [(X+32) || <<X>> <= <<"ABCDEFG">>],
   89:     ?line <<1:32/little,2:32/little,3:32/little,4:32/little>> =
   90: 	<< <<X:32/little>> || X <- [1,2,3,4] >>,
   91:     ?line [256,512,768,1024] =
   92: 	[X || <<X:16/little>> <= <<1:16,2:16,3:16,4:16>>],
   93:   ok.
   94: 
   95: extended_bit_aligned(Config) when is_list(Config) ->
   96:     ?line <<$a:7,$b:7,$c:7,$d:7,$e:7,$f:7,$g:7>> =
   97: 	<< <<(X+32):7>> || X <- "ABCDEFG" >>,
   98:     ?line "ABCDEFG" = [(X-32) || <<X:7>> <= <<$a:7,$b:7,$c:7,$d:7,$e:7,$f:7,$g:7>>],
   99:     ?line <<1:31/little,2:31/little,3:31/little,4:31/little>> =
  100: 	<< <<X:31/little>> || X <- [1,2,3,4] >>,
  101:     ?line [256,512,768,1024] =
  102: 	[X || <<X:15/little>> <= <<1:15,2:15,3:15,4:15>>],
  103:     ok.
  104: 
  105: mixed(Config) when is_list(Config) ->
  106:     ?line <<2,3,3,4,4,5,5,6>> =
  107: 	<< <<(X+Y)>> || <<X>> <= <<1,2,3,4>>, <<Y>> <= <<1,2>> >>,
  108:     ?line <<2,3,3,4,4,5,5,6>> =
  109: 	<< <<(X+Y)>> || <<X>> <= <<1,2,3,4>>, Y <- [1,2] >>,
  110:     ?line <<2,3,3,4,4,5,5,6>> =
  111: 	<< <<(X+Y)>> || X <- [1,2,3,4], Y <- [1,2] >>,
  112:     ?line [2,3,3,4,4,5,5,6] =
  113: 	[(X+Y) || <<X>> <= <<1,2,3,4>>, <<Y>> <= <<1,2>>],
  114:     ?line [2,3,3,4,4,5,5,6] =
  115: 	[(X+Y) || <<X>> <= <<1,2,3,4>>, Y <- [1,2]],
  116:     ?line <<2:3,3:3,3:3,4:3,4:3,5:3,5:3,6:3>> =
  117: 	<< <<(X+Y):3>> || <<X:3>> <= <<1:3,2:3,3:3,4:3>>, <<Y:3>> <= <<1:3,2:3>> >>,
  118:     ?line <<2:3,3:3,3:3,4:3,4:3,5:3,5:3,6:3>> =
  119: 	<< <<(X+Y):3>> || <<X:3>> <= <<1:3,2:3,3:3,4:3>>, Y <- [1,2] >>,
  120:     ?line <<2:3,3:3,3:3,4:3,4:3,5:3,5:3,6:3>> =
  121: 	<< <<(X+Y):3>> || X <- [1,2,3,4], Y <- [1,2] >>,
  122:     ?line [2,3,3,4,4,5,5,6] =
  123: 	[(X+Y) || <<X:3>> <= <<1:3,2:3,3:3,4:3>>, <<Y:3>> <= <<1:3,2:3>>],
  124:     ?line [2,3,3,4,4,5,5,6] =
  125: 	[(X+Y) || <<X:3>> <= <<1:3,2:3,3:3,4:3>>, Y <- [1,2]],
  126:     ok.