1: %%
    2: %% %CopyrightBegin%
    3: %% 
    4: %% Copyright Ericsson AB 1997-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(list_bif_SUITE).
   21: -include_lib("test_server/include/test_server.hrl").
   22: 
   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,
   25: 	 init_per_testcase/2,end_per_testcase/2]).
   26: -export([hd_test/1,tl_test/1,t_length/1,t_list_to_pid/1,
   27: 	 t_list_to_float/1,t_list_to_integer/1]).
   28: 
   29: 
   30: suite() -> [{ct_hooks,[ts_install_cth]}].
   31: 
   32: all() -> 
   33:     [hd_test, tl_test, t_length, t_list_to_pid,
   34:      t_list_to_float, t_list_to_integer].
   35: 
   36: groups() -> 
   37:     [].
   38: 
   39: init_per_suite(Config) ->
   40:     Config.
   41: 
   42: end_per_suite(_Config) ->
   43:     ok.
   44: 
   45: init_per_group(_GroupName, Config) ->
   46:     Config.
   47: 
   48: end_per_group(_GroupName, Config) ->
   49:     Config.
   50: 
   51: 
   52: init_per_testcase(_Case, Config) ->
   53:     ?line Dog = test_server:timetrap(test_server:seconds(60)),
   54:     [{watchdog,Dog}|Config].
   55: 
   56: end_per_testcase(_Case, Config) ->
   57:     Dog = ?config(watchdog, Config),
   58:     test_server:timetrap_cancel(Dog),
   59:     ok.
   60: 
   61: t_list_to_integer(suite) ->
   62:     [];
   63: t_list_to_integer(doc) ->
   64:     ["tests list_to_integer and string:to_integer"];
   65: t_list_to_integer(Config) when is_list(Config) ->
   66:     ?line {'EXIT',{badarg,_}} = (catch list_to_integer("12373281903728109372810937209817320981321ABC")),
   67:     ?line 12373281903728109372810937209817320981321 = (catch list_to_integer("12373281903728109372810937209817320981321")),
   68:     ?line 12373 = (catch list_to_integer("12373")),
   69:     ?line -12373 =  (catch list_to_integer("-12373")),
   70:     ?line 12373 = (catch list_to_integer("+12373")),
   71:     ?line {'EXIT',{badarg,_}} = ( catch list_to_integer(abc)),
   72:     ?line {'EXIT',{badarg,_}} = (catch list_to_integer("")),
   73:     ?line {12373281903728109372810937209817320981321,"ABC"} = string:to_integer("12373281903728109372810937209817320981321ABC"),
   74:     ?line {-12373281903728109372810937209817320981321,"ABC"} = string:to_integer("-12373281903728109372810937209817320981321ABC"),
   75:     ?line {12,[345]} = string:to_integer([$1,$2,345]),
   76:     ?line {12,[a]} = string:to_integer([$1,$2,a]),
   77:     ?line {error,no_integer} = string:to_integer([$A]),
   78:     ?line {error,not_a_list} = string:to_integer($A),
   79:     ok.
   80: 
   81: %% Test hd/1 with correct and incorrect arguments.
   82: hd_test(Config) when is_list(Config) ->
   83:     ?line $h = hd(id("hejsan")),
   84:     ?line case catch hd(id($h)) of
   85: 	      {'EXIT', {badarg, _}} -> ok;
   86: 	      Res ->
   87: 		  Str=io_lib:format("hd/1 with incorrect args "++
   88: 				    "succeeded.~nResult: ~p", [Res]),
   89: 		  test_server:fail(Str)
   90: 	  end,
   91:     ok.
   92: 
   93: 
   94: %% Test tl/1 with correct and incorrect arguments.
   95: tl_test(Config) when is_list(Config) ->
   96:     ?line "ejsan" = tl(id("hejsan")),
   97:     ?line case catch tl(id(104)) of
   98: 	      {'EXIT', {badarg, _}} ->
   99: 		  ok;
  100: 	      Res ->
  101: 		  Str=io_lib:format("tl/1 with incorrect args "++
  102: 				   "succeeded.~nResult: ~p", [Res]),
  103: 		  test_server:fail(Str)
  104: 	  end,
  105:     ok.
  106: 
  107: 
  108: %% Test length/1 with correct and incorrect arguments.
  109: 
  110: t_length(Config) when is_list(Config) ->
  111:     ?line 0 = length(""),
  112:     ?line 0 = length([]),
  113:     ?line 1 = length([1]),
  114:     ?line 2 = length([1,a]),
  115:     ?line 2 = length("ab"),
  116:     ?line 3 = length("abc"),
  117:     ?line 4 = length(id([x|"abc"])),
  118:     ?line 6 = length("hejsan"),
  119:     ?line {'EXIT',{badarg,_}} = (catch length(id([a,b|c]))),
  120:     ?line case catch length({tuple}) of
  121: 	      {'EXIT', {badarg, _}} ->
  122: 		  ok;
  123: 	      Res ->
  124: 		  Str = io_lib:format("length/1 with incorrect args "++
  125: 				      "succeeded.~nResult: ~p", [Res]),
  126: 		  ?line test_server:fail(Str)
  127: 	  end,
  128:     ok.
  129: 	      
  130: 
  131: %% Test list_to_pid/1 with correct and incorrect arguments.
  132: 
  133: t_list_to_pid(Config) when is_list(Config) ->
  134:     ?line Me = self(),
  135:     ?line MyListedPid = pid_to_list(Me),
  136:     ?line Me = list_to_pid(MyListedPid),
  137:     ?line case catch list_to_pid(id("Incorrect list")) of
  138: 	      {'EXIT', {badarg, _}} ->
  139: 		  ok;
  140: 	      Res ->
  141: 		  Str=io_lib:format("list_to_pid/1 with incorrect "++
  142: 				   "arg succeeded.~nResult: ~p",
  143: 				    [Res]),
  144: 		  test_server:fail(Str)
  145: 	  end,
  146:     ok.
  147: 
  148: 
  149: %% Test list_to_float/1 with correct and incorrect arguments.
  150: 
  151: t_list_to_float(Config) when is_list(Config) ->
  152:     ?line 5.89000 = list_to_float(id("5.89")),
  153:     ?line 5.89898 = list_to_float(id("5.89898")),
  154:     ?line case catch list_to_float(id("58")) of
  155: 	      {'EXIT', {badarg, _}} -> ok;
  156: 	      Res ->
  157: 		  Str=io_lib:format("list_to_float with incorrect "++
  158: 				   "arg succeeded.~nResult: ~p",
  159: 				    [Res]),
  160: 		  test_server:fail(Str)
  161: 	  end,
  162:     ok.
  163: 
  164: id(I) -> I.
  165: 
  166: