acceptor_SUITE.erl 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. %% Copyright (c) 2011-2012, Loïc Hoguin <essen@ninenines.eu>
  2. %%
  3. %% Permission to use, copy, modify, and/or distribute this software for any
  4. %% purpose with or without fee is hereby granted, provided that the above
  5. %% copyright notice and this permission notice appear in all copies.
  6. %%
  7. %% THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  8. %% WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  9. %% MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  10. %% ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  11. %% WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  12. %% ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  13. %% OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  14. -module(acceptor_SUITE).
  15. -include_lib("common_test/include/ct.hrl").
  16. -export([all/0, groups/0, init_per_suite/1, end_per_suite/1]). %% ct.
  17. -export([tcp_echo/1]). %% tcp.
  18. %% ct.
  19. all() ->
  20. [{group, tcp}].
  21. groups() ->
  22. Tests = [tcp_echo],
  23. [{tcp, Tests}].
  24. init_per_suite(Config) ->
  25. application:start(ranch),
  26. Config.
  27. end_per_suite(_) ->
  28. application:stop(ranch),
  29. ok.
  30. %% tcp.
  31. tcp_echo(_) ->
  32. {ok, _} = ranch:start_listener(tcp_echo, 1,
  33. ranch_tcp, [{port, 0}], echo_protocol, []),
  34. Port = ranch:get_port(tcp_echo),
  35. {ok, Socket} = gen_tcp:connect("localhost", Port,
  36. [binary, {active, false}, {packet, raw}]),
  37. ok = gen_tcp:send(Socket, <<"Ranch is working!">>),
  38. {ok, <<"Ranch is working!">>} = gen_tcp:recv(Socket, 0, 1000),
  39. ok = ranch:stop_listener(tcp_echo),
  40. {error, closed} = gen_tcp:recv(Socket, 0, 1000),
  41. ok.