Skip to content

Commit

Permalink
Removed proper and switched to EQC.
Browse files Browse the repository at this point in the history
  • Loading branch information
Licenser committed Jul 2, 2015
1 parent 32db6f6 commit 8e4fbdd
Show file tree
Hide file tree
Showing 7 changed files with 169 additions and 99 deletions.
File renamed without changes.
2 changes: 1 addition & 1 deletion rebar.config
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
{deps,
[
{lager, ".*", {git, "git://github.com/basho/lager.git", {tag, "1.2.2"}}},
{proper, ".*", {git, "git://github.com/manopapad/proper.git", {branch, master}}}
{fqc, ".*", {git, "git://github.com/project-fifo/fqc.git", {tag, "0.1.4"}}}
]}.
13 changes: 0 additions & 13 deletions src/dhcp.erl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

-ignore_xref([ip_to_tpl/1, tpl_to_ip/1]).
-ifdef(TEST).
-include_lib("proper/include/proper.hrl").
-include_lib("eunit/include/eunit.hrl").
-endif.

Expand All @@ -31,18 +30,6 @@ tpl_to_ip({A, B, C, D}) ->

-ifdef(TEST).

prop_ip_tpl_conversion() ->
?FORALL(Tpl, ip_tpl(),
begin
EncDecTpl = ip_to_tpl(tpl_to_ip(Tpl)),
EncDecTpl =:= Tpl
end).

propper_test() ->
?assertEqual(true, proper:check_spec({dhcp, ip_to_tpl, 1}, [{to_file, user}])),
?assertEqual(true, proper:check_spec({dhcp, tpl_to_ip, 1}, [{to_file, user}])),
?assertEqual([], proper:module(?MODULE, [{to_file, user}])).

ip2tpl_test() ->
?assertEqual({1,2,3,4}, ip_to_tpl(16#01020304)),
?assertEqual({0,0,0,0}, ip_to_tpl(16#00000000)),
Expand Down
75 changes: 1 addition & 74 deletions src/dhcp_package.erl
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
-module(dhcp_package).

-ifdef(TEST).
-include_lib("proper/include/proper.hrl").
-include_lib("eunit/include/eunit.hrl").
-export([decode_htype/1, encode_htype/1,
decode_op/1, encode_op/1]).
-compile(export_all).
-endif.

-include("dhcp.hrl").
Expand Down Expand Up @@ -947,77 +945,6 @@ check_option(P, [], [Forbidden | R]) ->

-ifdef(TEST).

null_terminated_string() ->
?LET(S,
list(range(1,255)),
list_to_binary(S)).

prop_mac_conversion() ->
?FORALL(Mac, mac(),
begin
EncDecMac = decode_mac(encode_mac(Mac)),
EncDecMac =:= Mac
end).

prop_op_conversion() ->
?FORALL(Op, dhcp:op(),
begin
EncDecOp = decode_op(encode_op(Op)),
EncDecOp =:= Op
end).

prop_ip_conversion() ->
?FORALL(IP, ip(),
begin
EncDecIP = decode_ip(encode_ip(IP)),
EncDecIP =:= IP
end).

prop_mt_conversion() ->
?FORALL(MT, message_type(),
begin
EncDecMT = decode_message_type(encode_message_type(MT)),
EncDecMT =:= MT
end).

prop_htype_conversion() ->
?FORALL(HType, htype(),
begin
EncDecHType = decode_htype(encode_htype(HType)),
EncDecHType =:= HType
end).

prop_string_conversion() ->
?FORALL(S, null_terminated_string(),
begin
EncDecS = decode_string(encode_string(S, byte_size(S) + 2)),
EncDecS =:= S
end).

prop_package_conversion() ->
?FORALL(P, dhcp:package(),
begin
PMt = set_option({message_type, P#dhcp_package.message_type}, P),
PMt1 = PMt#dhcp_package{
%% We need make sure options is sorted for compairison
options = lists:sort(PMt#dhcp_package.options),
%% We need to work around the fact that there is no notation for
%% lists with a exact number of elements
flags = ordsets:from_list(PMt#dhcp_package.flags),
%% There is no way to notate binarys that do not contain 0's
%% So we eliminate them and test the conversion sepperately
sname = <<>>,
file = <<>>},
{ok, EncP} = encode(PMt1),
{ok, EncDecP} = decode(EncP),
EncDecP =:= PMt1
end).

propper_test() ->
proper:check_spec({dhcp_package, get_option, 2}, [{to_file, user}, long_result]),
proper:check_spec({dhcp_package, get_option, 3}, [{to_file, user}, long_result]),

?assertEqual([], proper:module(?MODULE, [{to_file, user}, long_result])).

str_decode_test() ->
?assertEqual(<<"a">>, decode_string(<<"a", 0:8>>)),
Expand Down
11 changes: 0 additions & 11 deletions src/dhcp_server.erl
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
-include("dhcp.hrl").

-ifdef(TEST).
-include_lib("proper/include/proper.hrl").
-include_lib("eunit/include/eunit.hrl").
-export([match/2, match_pkg/2,
match_mac/2, match_fields/2, match_opts/2]).
Expand Down Expand Up @@ -238,13 +237,3 @@ match_opts(P, [{O, V} | Fs]) ->
match_fields(P, Fs);
match_opts(_, []) ->
true.

-ifdef(TEST).
propper_test() ->
?assertEqual(true, proper:check_spec({dhcp_server, match, 2}, [{to_file, user}, long_result])),
?assertEqual(true, proper:check_spec({dhcp_server, match_pkg, 2}, [{to_file, user}, long_result])),
?assertEqual(true, proper:check_spec({dhcp_server, match_mac, 2}, [{to_file, user}, long_result])),
?assertEqual(true, proper:check_spec({dhcp_server, match_fields, 2}, [{to_file, user}, long_result])),
?assertEqual(true, proper:check_spec({dhcp_server, match_opts, 2}, [{to_file, user}, long_result])).

-endif.
27 changes: 27 additions & 0 deletions test/dhcp_eqc.erl
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
-module(dhcp_eqc).

-define(M, dhcp).

-ifdef(TEST).
-ifdef(EQC).
-include_lib("fqc/include/fqc.hrl").
-include_lib("eunit/include/eunit.hrl").
-compile(export_all).

-include("dhcp.hrl").

byte() ->
choose(0,255).

ip_tpl() ->
{byte(), byte(), byte(), byte()}.

prop_ip_tpl_conversion() ->
?FORALL(Tpl, ip_tpl(),
begin
EncDecTpl = ?M:ip_to_tpl(?M:tpl_to_ip(Tpl)),
EncDecTpl =:= Tpl
end).

-endif.
-endif.
140 changes: 140 additions & 0 deletions test/dhcp_package_eqc.erl
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
-module(dhcp_package_eqc).

-define(M, dhcp_package).

-ifdef(TEST).
-ifdef(EQC).
-include_lib("fqc/include/fqc.hrl").
-include_lib("eunit/include/eunit.hrl").
-compile(export_all).

-include("dhcp.hrl").

%%%===================================================================
%%% Generators
%%%===================================================================

byte() ->
choose(0,255).

null_terminated_string() ->
?LET(S,
list(choose(1,255)),
list_to_binary(S)).

mac() ->
{byte(),byte(),byte(),byte(),byte(),byte()}.

op() ->
oneof([request, reply]).

ip() ->
choose(0, 4294967295).

message_type() ->
oneof([discover, offer, request, decline,
ack, nck, release, inform, force_renew]).

htype() ->
oneof([ethernet,
experiemental_ethernet,
ax25,
proteon_token_ring,
chaos,
ieee802,
arcnet,
hyperchannel,
lanstar,
autonet_short_address,
localtalk,
localnet,
ultra_link,
smds,
frame_relay,
atm16,
hdlc,
fibre_channel,
atm19,
serial_line,
atm21,
mil_std_188_220,
metricom,
ieee1394,
mapos,
twinaxial,
eui64,
hiparp,
ip_over_iso_7816_3,
arpsec,
ipsec_tunnel,
infiniband,
cai_tia_102]).

%%%===================================================================
%%% Properties
%%%===================================================================


prop_mac_conversion() ->
?FORALL(Mac, mac(),
begin
EncDecMac = ?M:decode_mac(?M:encode_mac(Mac)),
EncDecMac =:= Mac
end).

prop_op_conversion() ->
?FORALL(Op, op(),
begin
EncDecOp = ?M:decode_op(?M:encode_op(Op)),
EncDecOp =:= Op
end).

prop_ip_conversion() ->
?FORALL(IP, ip(),
begin
EncDecIP = ?M:decode_ip(?M:encode_ip(IP)),
EncDecIP =:= IP
end).

prop_mt_conversion() ->
?FORALL(MT, message_type(),
begin
EncDecMT = ?M:decode_message_type(?M:encode_message_type(MT)),
EncDecMT =:= MT
end).

prop_htype_conversion() ->
?FORALL(HType, htype(),
begin
EncDecHType = ?M:decode_htype(?M:encode_htype(HType)),
EncDecHType =:= HType
end).

prop_string_conversion() ->
?FORALL(S, null_terminated_string(),
begin
EncDecS = ?M:decode_string(?M:encode_string(S, byte_size(S) + 2)),
EncDecS =:= S
end).

%% prop_package_conversion() ->
%% ?FORALL(P, dhcp:package(),
%% begin
%% PMt = set_option({message_type, P#dhcp_package.message_type}, P),
%% PMt1 = PMt#dhcp_package{
%% %% We need make sure options is sorted for compairison
%% options = lists:sort(PMt#dhcp_package.options),
%% %% We need to work around the fact that there is no notation for
%% %% lists with a exact number of elements
%% flags = ordsets:from_list(PMt#dhcp_package.flags),
%% %% There is no way to notate binarys that do not contain 0's
%% %% So we eliminate them and test the conversion sepperately
%% sname = <<>>,
%% file = <<>>},
%% {ok, EncP} = encode(PMt1),
%% {ok, EncDecP} = decode(EncP),
%% EncDecP =:= PMt1
%% end).

-endif.
-endif.

0 comments on commit 8e4fbdd

Please sign in to comment.