diff options
Diffstat (limited to 'lib/stdlib/test/base64_SUITE.erl')
-rw-r--r-- | lib/stdlib/test/base64_SUITE.erl | 98 |
1 files changed, 28 insertions, 70 deletions
diff --git a/lib/stdlib/test/base64_SUITE.erl b/lib/stdlib/test/base64_SUITE.erl index 75eebba6c6..d0abe5c961 100644 --- a/lib/stdlib/test/base64_SUITE.erl +++ b/lib/stdlib/test/base64_SUITE.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 2007-2013. All Rights Reserved. +%% Copyright Ericsson AB 2007-2016. All Rights Reserved. %% %% Licensed under the Apache License, Version 2.0 (the "License"); %% you may not use this file except in compliance with the License. @@ -23,9 +23,7 @@ -include_lib("common_test/include/ct.hrl"). %% Test server specific exports --export([all/0, suite/0,groups/0,init_per_suite/1, end_per_suite/1, - init_per_group/2,end_per_group/2, - init_per_testcase/2, end_per_testcase/2]). +-export([all/0, suite/0, groups/0, group/1]). %% Test cases must be exported. -export([base64_encode/1, base64_decode/1, base64_otp_5635/1, @@ -33,49 +31,29 @@ 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]. - -end_per_testcase(_, Config) -> - Dog = ?config(watchdog, Config), - test_server:timetrap_cancel(Dog), - ok. - %%------------------------------------------------------------------------- %% Test cases starts here. %%------------------------------------------------------------------------- -suite() -> [{ct_hooks,[ts_install_cth]}]. -all() -> +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, {group, roundtrip}]. -groups() -> +groups() -> [{roundtrip, [parallel], [roundtrip_1, roundtrip_2, roundtrip_3, roundtrip_4]}]. -init_per_suite(Config) -> - Config. - -end_per_suite(_Config) -> - ok. - -init_per_group(_GroupName, Config) -> - Config. - -end_per_group(_GroupName, Config) -> - Config. - - +group(roundtrip) -> + %% valgrind needs a lot of time + [{timetrap,{minutes,10}}]. %%------------------------------------------------------------------------- -base64_encode(doc) -> - ["Test base64:encode/1."]; -base64_encode(suite) -> - []; +%% Test base64:encode/1. base64_encode(Config) when is_list(Config) -> %% Two pads <<"QWxhZGRpbjpvcGVuIHNlc2FtZQ==">> = @@ -83,17 +61,14 @@ base64_encode(Config) when is_list(Config) -> %% One pad <<"SGVsbG8gV29ybGQ=">> = base64:encode(<<"Hello World">>), %% No pad - "QWxhZGRpbjpvcGVuIHNlc2Ft" = + "QWxhZGRpbjpvcGVuIHNlc2Ft" = base64:encode_to_string("Aladdin:open sesam"), - + "MDEyMzQ1Njc4OSFAIzBeJiooKTs6PD4sLiBbXXt9" = 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">> = @@ -101,7 +76,7 @@ base64_decode(Config) when is_list(Config) -> %% One pad <<"Hello World">> = base64:decode(<<"SGVsbG8gV29ybGQ=">>), %% No pad - <<"Aladdin:open sesam">> = + <<"Aladdin:open sesam">> = base64:decode("QWxhZGRpbjpvcGVuIHNlc2Ft"), Alphabet = list_to_binary(lists:seq(0, 255)), @@ -117,28 +92,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), @@ -148,10 +113,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. @@ -159,10 +121,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">>), @@ -202,10 +162,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">>), @@ -233,7 +191,7 @@ mime_decode_to_string(Config) when is_list(Config) -> %% One pad to ignore, followed by more text "Hello World!!" = base64:mime_decode_to_string(<<"SGVsb)(G8gV29ybGQ=h IQ= =">>), %% No pad - "Aladdin:open sesam" = + "Aladdin:open sesam" = base64:mime_decode_to_string("QWxhZGRpbjpvcG¤\")(VuIHNlc2Ft"), %% Encoded base 64 strings may be divided by non base 64 chars. %% In this cases whitespaces. @@ -339,8 +297,8 @@ 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, Acc) -> + random_byte_list(N-1, [rand:uniform(255)|Acc]). make_big_binary(N) -> list_to_binary(mbb(N, [])). |