1: %% 2: %% %CopyrightBegin% 3: %% 4: %% Copyright Ericsson AB 1999-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_tail_no_opt_SUITE). 21: 22: -author('bjorn@erix.ericsson.se'). 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,aligned/1,unaligned/1,zero_tail/1]). 25: 26: -include_lib("test_server/include/test_server.hrl"). 27: 28: suite() -> [{ct_hooks,[ts_install_cth]}]. 29: 30: all() -> 31: [aligned, unaligned, zero_tail]. 32: 33: groups() -> 34: []. 35: 36: init_per_suite(Config) -> 37: Config. 38: 39: end_per_suite(_Config) -> 40: ok. 41: 42: init_per_group(_GroupName, Config) -> 43: Config. 44: 45: end_per_group(_GroupName, Config) -> 46: Config. 47: 48: 49: aligned(doc) -> "Test aligned tails."; 50: aligned(Config) when is_list(Config) -> 51: ?line Tail1 = mkbin([]), 52: ?line {258,Tail1} = al_get_tail_used(mkbin([1,2])), 53: ?line Tail2 = mkbin(lists:seq(1, 127)), 54: ?line {35091,Tail2} = al_get_tail_used(mkbin([137,19|Tail2])), 55: 56: ?line 64896 = al_get_tail_unused(mkbin([253,128])), 57: ?line 64895 = al_get_tail_unused(mkbin([253,127|lists:seq(42, 255)])), 58: 59: ?line Tail3 = mkbin(lists:seq(0, 19)), 60: ?line {0,Tail1} = get_dyn_tail_used(Tail1, 0), 61: ?line {0,Tail3} = get_dyn_tail_used(mkbin([Tail3]), 0), 62: ?line {73,Tail3} = get_dyn_tail_used(mkbin([73|Tail3]), 8), 63: 64: ?line 0 = get_dyn_tail_unused(mkbin([]), 0), 65: ?line 233 = get_dyn_tail_unused(mkbin([233]), 8), 66: ?line 23 = get_dyn_tail_unused(mkbin([23,22,2]), 8), 67: ok. 68: 69: al_get_tail_used(<<A:16,T/binary>>) -> {A,T}. 70: al_get_tail_unused(<<A:16,_/binary>>) -> A. 71: 72: unaligned(doc) -> "Test that an non-aligned tail cannot be matched out."; 73: unaligned(Config) when is_list(Config) -> 74: ?line {'EXIT',{function_clause,_}} = (catch get_tail_used(mkbin([42]))), 75: ?line {'EXIT',{{badmatch,_},_}} = (catch get_dyn_tail_used(mkbin([137]), 3)), 76: ?line {'EXIT',{function_clause,_}} = (catch get_tail_unused(mkbin([42,33]))), 77: ?line {'EXIT',{{badmatch,_},_}} = (catch get_dyn_tail_unused(mkbin([44]), 7)), 78: ok. 79: 80: get_tail_used(<<A:1,T/binary>>) -> {A,T}. 81: 82: get_tail_unused(<<A:15,_/binary>>) -> A. 83: 84: get_dyn_tail_used(Bin, Sz) -> 85: <<A:Sz,T/binary>> = Bin, 86: {A,T}. 87: 88: get_dyn_tail_unused(Bin, Sz) -> 89: <<A:Sz,_/binary>> = Bin, 90: A. 91: 92: zero_tail(doc) -> "Test that zero tails are tested correctly."; 93: zero_tail(Config) when is_list(Config) -> 94: ?line 7 = (catch test_zero_tail(mkbin([7]))), 95: ?line {'EXIT',{function_clause,_}} = (catch test_zero_tail(mkbin([1,2]))), 96: ?line {'EXIT',{function_clause,_}} = (catch test_zero_tail2(mkbin([1,2,3]))), 97: ok. 98: 99: test_zero_tail(<<A:8>>) -> A. 100: 101: test_zero_tail2(<<_A:4,_B:4>>) -> ok. 102: 103: mkbin(L) when is_list(L) -> list_to_binary(L). 104: 105: 106: 107: