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_tail_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: aligned/1,unaligned/1,zero_tail/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: [aligned, unaligned, zero_tail]. 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: aligned(doc) -> "Test aligned tails."; 67: aligned(Config) when is_list(Config) -> 68: ?line Tail1 = mkbin([]), 69: ?line {258,Tail1} = al_get_tail_used(mkbin([1,2])), 70: ?line Tail2 = mkbin(lists:seq(1, 127)), 71: ?line {35091,Tail2} = al_get_tail_used(mkbin([137,19|Tail2])), 72: 73: ?line 64896 = al_get_tail_unused(mkbin([253,128])), 74: ?line 64895 = al_get_tail_unused(mkbin([253,127|lists:seq(42, 255)])), 75: 76: ?line Tail3 = mkbin(lists:seq(0, 19)), 77: ?line {0,Tail1} = get_dyn_tail_used(Tail1, 0), 78: ?line {0,Tail3} = get_dyn_tail_used(mkbin([Tail3]), 0), 79: ?line {73,Tail3} = get_dyn_tail_used(mkbin([73|Tail3]), 8), 80: 81: ?line 0 = get_dyn_tail_unused(mkbin([]), 0), 82: ?line 233 = get_dyn_tail_unused(mkbin([233]), 8), 83: ?line 23 = get_dyn_tail_unused(mkbin([23,22,2]), 8), 84: ok. 85: 86: al_get_tail_used(<<A:16,T/binary>>) -> {A,T}. 87: al_get_tail_unused(<<A:16,_/binary>>) -> A. 88: 89: unaligned(doc) -> "Test that an non-aligned tail cannot be matched out."; 90: unaligned(Config) when is_list(Config) -> 91: ?line {'EXIT',{function_clause,_}} = (catch get_tail_used(mkbin([42]))), 92: ?line {'EXIT',{{badmatch,_},_}} = (catch get_dyn_tail_used(mkbin([137]), 3)), 93: ?line {'EXIT',{function_clause,_}} = (catch get_tail_unused(mkbin([42,33]))), 94: ?line {'EXIT',{{badmatch,_},_}} = (catch get_dyn_tail_unused(mkbin([44]), 7)), 95: ok. 96: 97: get_tail_used(<<A:1,T/binary>>) -> {A,T}. 98: 99: get_tail_unused(<<A:15,_/binary>>) -> A. 100: 101: get_dyn_tail_used(Bin, Sz) -> 102: <<A:Sz,T/binary>> = Bin, 103: {A,T}. 104: 105: get_dyn_tail_unused(Bin, Sz) -> 106: <<A:Sz,_/binary>> = Bin, 107: A. 108: 109: zero_tail(doc) -> "Test that zero tails are tested correctly."; 110: zero_tail(Config) when is_list(Config) -> 111: ?line 7 = (catch test_zero_tail(mkbin([7]))), 112: ?line {'EXIT',{function_clause,_}} = (catch test_zero_tail(mkbin([1,2]))), 113: ?line {'EXIT',{function_clause,_}} = (catch test_zero_tail2(mkbin([1,2,3]))), 114: ok. 115: 116: test_zero_tail(<<A:8>>) -> A. 117: 118: test_zero_tail2(<<_A:4,_B:4>>) -> ok. 119: 120: mkbin(L) when is_list(L) -> list_to_binary(L).