diff options
Diffstat (limited to 'lib/stdlib/test/base64_SUITE.erl')
-rw-r--r-- | lib/stdlib/test/base64_SUITE.erl | 121 |
1 files changed, 55 insertions, 66 deletions
diff --git a/lib/stdlib/test/base64_SUITE.erl b/lib/stdlib/test/base64_SUITE.erl index b28df94221..9176a3664a 100644 --- a/lib/stdlib/test/base64_SUITE.erl +++ b/lib/stdlib/test/base64_SUITE.erl @@ -1,19 +1,19 @@ -%% -*- coding: utf-8 -*- %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 2007-2012. All Rights Reserved. +%% Copyright Ericsson AB 2007-2016. All Rights Reserved. %% -%% The contents of this file are subject to the Erlang Public License, -%% Version 1.1, (the "License"); you may not use this file except in -%% compliance with the License. You should have received a copy of the -%% Erlang Public License along with this software. If not, it can be -%% retrieved online at http://www.erlang.org/. -%% -%% Software distributed under the License is distributed on an "AS IS" -%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See -%% the License for the specific language governing rights and limitations -%% under the License. +%% Licensed under the Apache License, Version 2.0 (the "License"); +%% you may not use this file except in compliance with the License. +%% You may obtain a copy of the License at +%% +%% http://www.apache.org/licenses/LICENSE-2.0 +%% +%% Unless required by applicable law or agreed to in writing, software +%% distributed under the License is distributed on an "AS IS" BASIS, +%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +%% See the License for the specific language governing permissions and +%% limitations under the License. %% %% %CopyrightEnd% %% @@ -30,30 +30,30 @@ %% Test cases must be exported. -export([base64_encode/1, base64_decode/1, base64_otp_5635/1, base64_otp_6279/1, big/1, illegal/1, mime_decode/1, - mime_decode_to_string/1, roundtrip/1]). + mime_decode_to_string/1, + roundtrip_1/1, roundtrip_2/1, roundtrip_3/1, roundtrip_4/1]). init_per_testcase(_, Config) -> - Dog = test_server:timetrap(?t:minutes(4)), - NewConfig = lists:keydelete(watchdog, 1, Config), - [{watchdog, Dog} | NewConfig]. + Config. -end_per_testcase(_, Config) -> - Dog = ?config(watchdog, Config), - test_server:timetrap_cancel(Dog), +end_per_testcase(_, _Config) -> ok. %%------------------------------------------------------------------------- %% Test cases starts here. %%------------------------------------------------------------------------- -suite() -> [{ct_hooks,[ts_install_cth]}]. +suite() -> + [{ct_hooks,[ts_install_cth]}, + {timetrap,{minutes,4}}]. all() -> [base64_encode, base64_decode, base64_otp_5635, base64_otp_6279, big, illegal, mime_decode, mime_decode_to_string, - roundtrip]. + {group, roundtrip}]. groups() -> - []. + [{roundtrip, [parallel], + [roundtrip_1, roundtrip_2, roundtrip_3, roundtrip_4]}]. init_per_suite(Config) -> Config. @@ -70,10 +70,7 @@ end_per_group(_GroupName, Config) -> %%------------------------------------------------------------------------- -base64_encode(doc) -> - ["Test base64:encode/1."]; -base64_encode(suite) -> - []; +%% Test base64:encode/1. base64_encode(Config) when is_list(Config) -> %% Two pads <<"QWxhZGRpbjpvcGVuIHNlc2FtZQ==">> = @@ -88,10 +85,7 @@ base64_encode(Config) when is_list(Config) -> base64:encode_to_string(<<"0123456789!@#0^&*();:<>,. []{}">>), ok. %%------------------------------------------------------------------------- -base64_decode(doc) -> - ["Test base64:decode/1."]; -base64_decode(suite) -> - []; +%% Test base64:decode/1. base64_decode(Config) when is_list(Config) -> %% Two pads <<"Aladdin:open sesame">> = @@ -115,28 +109,18 @@ base64_decode(Config) when is_list(Config) -> <<"MDEy MzQ1Njc4 \tOSFAIzBeJ \niooKTs6 PD4sLi \r\nBbXXt9">>), ok. %%------------------------------------------------------------------------- -base64_otp_5635(doc) -> - ["OTP-5635: Some data doesn't pass through base64:decode/1 " - "correctly"]; -base64_otp_5635(suite) -> - []; +%% OTP-5635: Some data doesn't pass through base64:decode/1 correctly. base64_otp_5635(Config) when is_list(Config) -> <<"===">> = base64:decode(base64:encode("===")), ok. %%------------------------------------------------------------------------- -base64_otp_6279(doc) -> - ["OTP-6279: Guard needed so that function fails in a correct" - "way for faulty input i.e. function_clause"]; -base64_otp_6279(suite) -> - []; +%% OTP-6279: Guard needed so that function fails in a correct +%% way for faulty input, i.e. function_clause. base64_otp_6279(Config) when is_list(Config) -> {'EXIT',{function_clause, _}} = (catch base64:decode("dGVzda==a")), ok. %%------------------------------------------------------------------------- -big(doc) -> - ["Encode and decode big binaries."]; -big(suite) -> - []; +%% Encode and decode big binaries. big(Config) when is_list(Config) -> Big = make_big_binary(300000), B = base64:encode(Big), @@ -146,10 +130,7 @@ big(Config) when is_list(Config) -> Big = base64:mime_decode(B), ok. %%------------------------------------------------------------------------- -illegal(doc) -> - ["Make sure illegal characters are rejected when decoding."]; -illegal(suite) -> - []; +%% Make sure illegal characters are rejected when decoding. illegal(Config) when is_list(Config) -> {'EXIT',{function_clause, _}} = (catch base64:decode("()")), ok. @@ -157,10 +138,8 @@ illegal(Config) when is_list(Config) -> %% mime_decode and mime_decode_to_string have different implementations %% so test both with the same input separately. Both functions have %% the same implementation for binary/string arguments. -mime_decode(doc) -> - ["Test base64:mime_decode/1."]; -mime_decode(suite) -> - []; +%% +%% Test base64:mime_decode/1. mime_decode(Config) when is_list(Config) -> %% Test correct padding <<"one">> = base64:mime_decode(<<"b25l">>), @@ -200,10 +179,8 @@ mime_decode(Config) when is_list(Config) -> %%------------------------------------------------------------------------- %% Repeat of mime_decode() tests -mime_decode_to_string(doc) -> - ["Test base64:mime_decode_to_string/1."]; -mime_decode_to_string(suite) -> - []; + +%% Test base64:mime_decode_to_string/1. mime_decode_to_string(Config) when is_list(Config) -> %% Test correct padding "one" = base64:mime_decode_to_string(<<"b25l">>), @@ -242,21 +219,33 @@ mime_decode_to_string(Config) when is_list(Config) -> %%------------------------------------------------------------------------- -roundtrip(Config) when is_list(Config) -> - Sizes = lists:seq(1, 255) ++ lists:seq(2400-5, 2440), - roundtrip_1(Sizes, []). +roundtrip_1(Config) when is_list(Config) -> + do_roundtrip(1). + +roundtrip_2(Config) when is_list(Config) -> + do_roundtrip(2). + +roundtrip_3(Config) when is_list(Config) -> + do_roundtrip(3). + +roundtrip_4(Config) when is_list(Config) -> + do_roundtrip(4). + +do_roundtrip(Offset) -> + Sizes = lists:seq(Offset, 255, 4) ++ lists:seq(2400-6+Offset, 2440, 4), + do_roundtrip_1(Sizes, []). -roundtrip_1([NextSize|Sizes], Current) -> +do_roundtrip_1([NextSize|Sizes], Current) -> Len = length(Current), io:format("~p", [Len]), - do_roundtrip(Current), + do_roundtrip_2(Current), Next = random_byte_list(NextSize - Len, Current), - roundtrip_1(Sizes, Next); -roundtrip_1([], Last) -> + do_roundtrip_1(Sizes, Next); +do_roundtrip_1([], Last) -> io:format("~p", [length(Last)]), - do_roundtrip(Last). + do_roundtrip_2(Last). -do_roundtrip(List) -> +do_roundtrip_2(List) -> Bin = list_to_binary(List), Base64Bin = base64:encode(List), Base64Bin = base64:encode(Bin), @@ -326,7 +315,7 @@ interleaved_ws_roundtrip_1([], Base64List, Bin, List) -> random_byte_list(0, Acc) -> Acc; random_byte_list(N, Acc) -> - random_byte_list(N-1, [random:uniform(255)|Acc]). + random_byte_list(N-1, [rand:uniform(255)|Acc]). make_big_binary(N) -> list_to_binary(mbb(N, [])). |