diff options
author | Henrik Nord <[email protected]> | 2014-09-30 09:42:52 +0200 |
---|---|---|
committer | Henrik Nord <[email protected]> | 2014-09-30 09:42:52 +0200 |
commit | 6cfa8feeca6d01d230f1837a01b1f0ae706da457 (patch) | |
tree | a86047f3dd0ce7138f08068c1ace3809b116cfff /lib/eldap/test | |
parent | 585052c164623a227e7ae8112b2a023872672159 (diff) | |
parent | 88d5c0edbd08e069bc20cf13fa90bca59eb43e86 (diff) | |
download | otp-6cfa8feeca6d01d230f1837a01b1f0ae706da457.tar.gz otp-6cfa8feeca6d01d230f1837a01b1f0ae706da457.tar.bz2 otp-6cfa8feeca6d01d230f1837a01b1f0ae706da457.zip |
Merge branch 'maint'
Diffstat (limited to 'lib/eldap/test')
-rw-r--r-- | lib/eldap/test/Makefile | 1 | ||||
-rw-r--r-- | lib/eldap/test/eldap_connections_SUITE.erl | 126 |
2 files changed, 127 insertions, 0 deletions
diff --git a/lib/eldap/test/Makefile b/lib/eldap/test/Makefile index 3c5810eece..24e71cebaa 100644 --- a/lib/eldap/test/Makefile +++ b/lib/eldap/test/Makefile @@ -28,6 +28,7 @@ INCLUDES= -I. -I ../include # ---------------------------------------------------- MODULES= \ + eldap_connections_SUITE \ eldap_basic_SUITE ERL_FILES= $(MODULES:%=%.erl) diff --git a/lib/eldap/test/eldap_connections_SUITE.erl b/lib/eldap/test/eldap_connections_SUITE.erl new file mode 100644 index 0000000000..4c8aa9c2cf --- /dev/null +++ b/lib/eldap/test/eldap_connections_SUITE.erl @@ -0,0 +1,126 @@ +%% +%% %CopyrightBegin% +%% +%% Copyright Ericsson AB 2012-2014. 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. +%% +%% %CopyrightEnd% +%% + +-module(eldap_connections_SUITE). + +-compile(export_all). + +-include_lib("common_test/include/ct.hrl"). +%-include_lib("eldap/include/eldap.hrl"). + + +all() -> + [ + tcp_connection, + tcp_inet6_connection, + tcp_connection_option, + tcp_inet6_connection_option + ]. + + +init_per_suite(Config) -> Config. + +end_per_suite(_Config) -> ok. + + +init_per_testcase(_TestCase, Config) -> + {ok,Sl} = gen_tcp:listen(0,[]), + {ok,Sl6} = gen_tcp:listen(0,[inet6]), + [{listen_socket,Sl}, {listen_socket6,Sl6} | Config]. + +end_per_testcase(_TestCase, Config) -> + catch gen_tcp:close( proplists:get_value(listen_socket, Config) ), + catch gen_tcp:close( proplists:get_value(listen_socket6, Config) ), + ok. + +%%%================================================================ +%%% +%%% Test cases +%%% +%%%---------------------------------------------------------------- +tcp_connection(Config) -> + do_tcp_connection(Config, listen_socket, "localhost", []). + +tcp_inet6_connection(Config) -> + do_tcp_connection(Config, listen_socket6, "::", [{tcpopts,[inet6]}]). + + +do_tcp_connection(Config, SockKey, Host, Opts) -> + Sl = proplists:get_value(SockKey, Config), + {ok,{_,Port}} = inet:sockname(Sl), + case eldap:open([Host], [{port,Port}|Opts]) of + {ok,_H} -> + case gen_tcp:accept(Sl,1000) of + {ok,_S} -> ok; + {error,timeout} -> ct:fail("server side accept timeout",[]) + end; + Other -> ct:fail("eldap:open failed: ~p",[Other]) + end. + +%%%---------------------------------------------------------------- +tcp_connection_option(Config) -> + do_tcp_connection_option(Config, listen_socket, "localhost", []). + +tcp_inet6_connection_option(Config) -> + do_tcp_connection_option(Config, listen_socket6, "::", [{tcpopts,[inet6]}]). + + +do_tcp_connection_option(Config, SockKey, Host, Opts) -> + Sl = proplists:get_value(SockKey, Config), + {ok,{_,Port}} = inet:sockname(Sl), + + %% Make an option value to test. The option must be implemented on all + %% platforms that we test on. Must check what the default value is + %% so we don't happen to choose that particular value. + {ok,[{linger,DefaultLinger}]} = inet:getopts(Sl, [linger]), + TestLinger = case DefaultLinger of + {false,_} -> {true,5}; + {true,_} -> {false,0} + end, + + case catch eldap:open([Host], + [{port,Port},{tcpopts,[{linger,TestLinger}]}|Opts]) of + {ok,H} -> + case gen_tcp:accept(Sl,1000) of + {ok,_} -> + case eldap:getopts(H, [{tcpopts,[linger]}]) of + {ok,[{tcpopts,[{linger,ActualLinger}]}]} -> + case ActualLinger of + TestLinger -> + ok; + DefaultLinger -> + ct:fail("eldap:getopts: 'linger' didn't change," + " got ~p (=default) expected ~p", + [ActualLinger,TestLinger]); + _ -> + ct:fail("eldap:getopts: bad 'linger', got ~p expected ~p", + [ActualLinger,TestLinger]) + end; + Other -> + ct:fail("eldap:getopts: bad result ~p",[Other]) + end; + {error,timeout} -> + ct:fail("server side accept timeout",[]) + end; + + Other -> + ct:fail("eldap:open failed: ~p",[Other]) + end. + +%%%---------------------------------------------------------------- |