Browse files

Added first test for client interface

  • Loading branch information...
1 parent d1910e1 commit cfff44903245e274581a4a214934d59e885c0eaa Gianfranco Alongi committed Mar 21, 2012
Showing with 59 additions and 0 deletions.
  1. +47 −0 Three/Solution/src/pubsub_client_port.erl
  2. +12 −0 Three/Solution/test/pubsub_client_port_tests.erl
View
47 Three/Solution/src/pubsub_client_port.erl
@@ -0,0 +1,47 @@
+%%%-------------------------------------------------------------------
+%%% @author Gianfranco Alongi <zenon@zentop.local>
+%%% @copyright (C) 2012, Gianfranco Alongi
+%%% Created : 21 Mar 2012 by Gianfranco Alongi <zenon@zentop.local>
+%%%-------------------------------------------------------------------
+-module(pubsub_client_port).
+-behaviour(gen_server).
+
+%% API
+-export([start_link/0,
+ get_type/1]).
+
+%% gen_server callbacks
+-export([init/1, handle_call/3, handle_cast/2, handle_info/2,
+ terminate/2, code_change/3]).
+
+-record(state, {type = none :: publish | subscribe | none}).
+
+%%%===================================================================
+start_link() ->
+ gen_server:start_link(?MODULE, [], []).
+
+-spec(get_type(pid()) -> publish | subscribe | none).
+get_type(Pid) ->
+ gen_server:call(Pid,get_type).
+
+%%%===================================================================
+init([]) ->
+ {ok, #state{}}.
+
+handle_call(get_type, _From, State) ->
+ {reply,State#state.type, State}.
+
+handle_cast(_Msg, State) ->
+ {noreply, State}.
+
+handle_info(_Info, State) ->
+ {noreply, State}.
+
+terminate(_Reason, _State) ->
+ ok.
+
+code_change(_OldVsn, State, _Extra) ->
+ {ok, State}.
+
+%%%===================================================================
+
View
12 Three/Solution/test/pubsub_client_port_tests.erl
@@ -0,0 +1,12 @@
+-module(pubsub_client_port_tests).
+-include_lib("eunit/include/eunit.hrl").
+
+just_started_test() ->
+ {ok,First} = pubsub_client_port:start_link(),
+ {ok,Second} = pubsub_client_port:start_link(),
+ ?assertEqual(none,pubsub_client_port:get_type(First)),
+ ?assertEqual(none,pubsub_client_port:get_type(Second)).
+
+
+
+

0 comments on commit cfff449

Please sign in to comment.