rendered paste body-module( avatar_test002_SUITE ).
%%% include the local copy of the record defintions
%%% which MUST be identical to the hrl file of the same
%%% name in ROOT/swarm/lib/avatar-V*/incude
-include("avatar_records.hrl").
%%% This test loads up a range of avatars
%%% then sends them a bunch of messages
%%% and then asks them to show state
%%%
%%% The message combinations include doing things
%%% and then undoing them
%%% Trusts followed by distrusts, etc, etc
%%% Trying to trust someone who blocks you
-export( [ all/1, test1/1,
test3/1, test4/1,
test5/1, test6/1,
test7/1
] ).
-export( [ init_per_testcase/2, fin_per_testcase/2 ] ).
-include( "../test_server/test_server.hrl" ).
%%% This module is the 2nd test module for the avatar module
%%% It uses the helper module "fake_avatar_for_test"
all( suite ) ->
[ test1, test3,
test4, test5,
test6, test7
].
%%**************************************
%%
%% test a suite of avatars
%%
%%***************************************
test1( suite ) ->
[ ];
test1( doc ) ->
[ "Simple test that the avatars have blank payloads" ];
test1( Config ) ->
Expected = "Showing trusted : none",
R1 = avatar:get_information("bjork", {"show trusted"}),
case R1 of
Expected ->
Results = {test1, ok};
Other ->
Results = exit({test1, fail, returned, Other})
end,
test_utilities:wait(),
{ok, [{_1, _2, _3, _4, Result}]} = socket:call(data_access,read_first_dispatch),
case Result of
Expected ->
{test1, ok};
_Else ->
exit({failed, test1, expected, Expected, got, Result})
end,
{ok, [Answer]} = socket:call(data_access,read_first_dispatch),
io:format("In ~p Answer ~p~n", [test1, Answer]),
data_access:delete_dispatch(Answer).
test3( suite ) ->
[ ];
test3( doc ) ->
[ "Complex case to see how avatars handle uns and dises" ];
test3( Config ) ->
avatar:trust_message("bjork", {"trust", "bill", "about", "heating oil"}),
test_utilities:wait(),
avatar:trust_message("bjork", {"untrust", "bill", "about", "heating oil"}),
test_utilities:wait(),
avatar:trust_message("bjork", {"distrust", "bill", "about", "heating oil"}),
test_utilities:wait(),
avatar:trust_message("bjork", {"undistrust", "bill", "about", "heating oil"}),
test_utilities:wait(),
avatar:trust_message("bjork", {"block", "bill", "about", "heating oil"}),
test_utilities:wait(),
avatar:trust_message("bjork", {"unblock", "bill", "about", "heating oil"}),
test_utilities:wait(),
test_utilities:clean_up(),
Expected = "Showing trusted : none",
R1 = avatar:get_information("bjork", {"show trusted"}),
case R1 of
Expected ->
Results = {test3, ok};
Other ->
Results = exit({fail, test3, returned, Other})
end,
test_utilities:wait(),
{ok, [{_1, _2, _3, _4, Result}]} = socket:call(data_access,read_first_dispatch),
case Result of
Expected ->
{test1, ok};
_Else ->
exit({failed, test3, expected, Expected, got, Result})
end,
{ok, [Answer]} = socket:call(data_access,read_first_dispatch),
io:format("In ~p Answer ~p~n", [test3, Answer]),
data_access:delete_dispatch(Answer).
test4( suite ) ->
[ ];
test4( doc ) ->
[ "Complex case to see how avatars handle trusts and distrusts" ];
test4( Config ) ->
avatar:trust_message("bjork", {"trust", "bill", "about", "heating oil"}),
avatar:trust_message("bjork", {"distrust", "bill", "about", "heating oil"}),
Expected = "Showing relationships : distrust bill about heating oil",
R1 = avatar:get_information("bjork", {"show relationships"}),
Avatar = socket:call(data_access,read_avatar,"bjork"),
Results =
case R1 of
Expected -> {test4, ok};
Other -> exit({fail, test4, returned, Other, avatar, Avatar})
end,
test_utilities:wait(),
{ok, [{_1, _2, _3, _4, Result}]} = socket:call(data_access,read_first_dispatch),
case Result of
Expected ->
{test1, ok};
_Else ->
exit({failed, test1, expected, Expected, got, Result})
end,
{ok, [Answer]} = socket:call(data_access,read_first_dispatch),
io:format("In ~p Answer ~p~n", [test1, Answer]),
data_access:delete_dispatch(Answer).
test5( suite ) ->
[ ];
test5( doc ) ->
[ "Complex case to see how avatars handle trusts and blocks" ];
test5( Config ) ->
avatar:trust_message("bill", {"block", "bjork", "about", "heating oil"}),
test_utilities:wait(),
avatar:trust_message("bjork", {"trust", "bill", "about", "heating oil"}),
Expected = "Showing relationships : blocked by bill about heating oil : trust bill about heating oil",
test_utilities:wait(),
R1 = avatar:get_information("bjork", {"show relationships"}),
case R1 of
Expected ->
Results = {test5, ok};
Other ->
Results = exit(fail, {test5, returned, Other})
end,
test_utilities:wait(),
{ok, [{_1, _2, _3, _4, Result}]} = socket:call(data_access,read_first_dispatch),
case Result of
Expected ->
{test1, ok};
_Else ->
exit({failed, test1, expected, Expected, got, Result})
end,
{ok, [Answer]} = socket:call(data_access,read_first_dispatch),
io:format("In ~p Answer ~p~n", [test1, Answer]),
data_access:delete_dispatch(Answer).
test6( suite ) ->
[ ];
test6( doc ) ->
[ "Complex case to see how 5 avatars, loads of messages" ];
test6( Config ) ->
%% Now call a slew of messages
%% bjork first
avatar:trust_message("bjork", {"block", "bennie", "about", "heating oil"}),
avatar:trust_message("bjork", {"trust", "bill"}),
avatar:trust_message("bjork", {"distrust", "banjo", "about", "lipstick"}),
avatar:trust_message("bjork", {"block", "bennie"}),
avatar:trust_message("bjork", {"try", "bennie"}),
%% bill second
avatar:trust_message("bill", {"block", "bob", "about", "heating oil"}),
avatar:trust_message("bill", {"untrust", "banjo", "about", "energy"}),
avatar:trust_message("bill", {"distrust", "bjork"}),
%% bob third
avatar:trust_message("bob", {"trust", "bill", "about", "heating oil"}),
test_utilities:wait(),
avatar:trust_message("bob", {"distrust", "banjo", "about", "legroom"}),
avatar:trust_message("bob", {"block", "banjo", "about", "heating oil"}),
%% bennie fourth
avatar:trust_message("bennie", {"try", "bill", "about", "pans"}),
avatar:trust_message("bennie", {"block", "bill", "about", "heating oil"}),
avatar:trust_message("bennie", {"trust", "bill", "about", "heating oil"}),
avatar:trust_message("bennie", {"untry", "bill", "about", "pans"}),
%% banjo last
avatar:trust_message("banjo", {"trust", "bennie", "about", "everything"}),
avatar:trust_message("banjo", {"block", "bjork", "about", "heating oil"}),
avatar:trust_message("banjo", {"unblock", "bob", "about", "heating oil"}),
avatar:trust_message("banjo", {"untrust", "bennie"}),
avatar:trust_message("banjo", {"undistrust", "bob", "about", "microphones"}),
test_utilities:clean_up(),
test_utilities:wait(),
Expected1 = "Showing trusted : trust bill about everything",
R1 = avatar:get_information("bjork", {"show trusted"}),
test_utilities:wait(),
io:format("Got to 1"),
Read_result = socket:call(data_access,read_first_dispatch),
io:format("Read_result after 1 is ~p~n", [Read_result]),
{ok, [{_A1, _B1, _C1, _D1, _E1}]} = Read_result,
io:format("Got to 1a"),
case test_utilities:equals(R1, Expected1) of
true ->
Results1 = {test6_1, ok};
false ->
Results1 = fail
end,
test_utilities:clean_up(),
Expected2 = "Showing trusted : none",
R2 = avatar:get_information("bill", {"show trusted"}),
test_utilities:wait(),
io:format("Got to 2"),
{ok, [{_1b, _2b, _3b, _4a, R2a}]} = socket:call(data_access,read_first_dispatch),
case test_utilities:equals(R2a, Expected2) of
true ->
Results2 = {test6_2, ok};
false ->
Results2 = fail
end,
test_utilities:clean_up(),
Expected3 = "Showing relationships : blocked by bill about heating oil : block banjo about heating oil : distrust banjo about legroom : trust bill about heating oil",
R3 = avatar:get_information("bob", {"show relationships"}),
test_utilities:wait(),
io:format("Got to 3"),
{ok, [{_1c, _2c, _3c, _4, R3a}]} = socket:call(data_access,read_first_dispatch),
case test_utilities:equals(R3a, Expected3) of
true ->
Results3 = {test6_3, ok};
false ->
Results3 = fail
end,
test_utilities:clean_up(),
Expected4 = "Showing trusted : trust bill about heating oil",
R4 = avatar:get_information("bennie", {"show trusted"}),
test_utilities:wait(),
io:format("Got to 4"),
{ok, [{_1d, _2d, _3d, _4d, R4d}]} = socket:call(data_access,read_first_dispatch),
case test_utilities:equals(R4d, Expected4) of
true ->
Results4 = {test6_4, ok};
false ->
Results4 = fail
end,
test_utilities:clean_up(),
Expected5 = "Showing trusted : none",
R5 = avatar:get_information("banjo", {"show trusted"}),
test_utilities:wait(),
io:format("Got to 5"),
{ok, [{_1e, _2e, _3e, _4e, R5e}]} = socket:call(data_access,read_first_dispatch),
case test_utilities:equals(R5e, Expected5) of
true ->
Results5 = {test6_5, ok};
false ->
Results5 = fail
end,
test_utilities:clean_up(),
if
not (Results1 == {test6_1, ok}) -> exit({fail1, expected, Expected1, got, R1});
not (Results2 == {test6_2, ok}) -> exit({fail2, expected, Expected2, got, R2});
not (Results3 == {test6_3, ok}) -> exit({fail3, expected, Expected3, got, R3});
not (Results4 == {test6_4, ok}) -> exit({fail4, expected, Expected4, got, R4});
not (Results5 == {test6_5, ok}) -> exit({fail5, expected, Expected5, got, R5});
true -> {test6, ok}
end.
test7( suite ) ->
[ ];
test7( doc ) ->
[ "Test that after password is set, it has changed." ];
test7( Config ) ->
Result1 = avatar:handle_password("bjork", {"get password"}),
Result2 = avatar:handle_password("bjork", {"set password", "cipher"}),
test_utilities:wait(),
{ok, [State]} = socket:call(data_access,read_avatar,"bjork"),
Result = State#state.password,
ErrorResult = "not set",
case Result of
ErrorResult ->
exit(fail, {"got error result", Result, "for password"});
_Other ->
{test7, ok}
end.
%%**************************************
%%
%% Common initialisation functions for
%% test functions
%%
%%***************************************
init_per_testcase( Testcase, Config ) -> % Gash the parameters cos they're not used
%%*************************************************
%%
%% Start up the application and the database
%% then load up some avatars
%%
%%*************************************************
%% Use Conrad's shim to start things up...
case shim_message1:run() of
ok -> ok;
Else -> exit(failed, {shim_message1, expected, ok, got, Else})
end,
Bobstate = #state{name = "bob", mobilephoneno = "07777000421"},
Billstate = #state{name = "bill", mobilephoneno = "07777000422"},
Benniestate = #state{name = "bennie", mobilephoneno = "07777000423"},
Banjostate = #state{name = "banjo", mobilephoneno = "07777000424"},
Bjorkstate = #state{name = "bjork", mobilephoneno = "07777000425"},
Result1 = socket:call(data_access,write_avatar,Bobstate),
Result2 = socket:call(data_access,write_avatar,Billstate),
Result3 = socket:call(data_access,write_avatar,Benniestate),
Result4 = socket:call(data_access,write_avatar,Banjostate),
Result5 = socket:call(data_access,write_avatar,Bjorkstate),
case [Result1, Result2, Result3, Result4, Result5] of
[ok, ok, ok, ok, ok] ->
test_utilities:clean_up(),
{avatar_test2_init_per_case, ok};
Else2 ->
{error, Else2}
end.
fin_per_testcase( Testcase, Config ) ->
shim_message1:close_down(),
{ avatar_test2_fin_per_case, ok }.